简体   繁体   English

Android - 如何在线性布局中使按钮更高?

[英]Android - How do I make the button taller in a linear layout?

I have a linear layout inside a relative layout, and I want to make the buttons 'taller' to fit the height of the linear layout. 我在相对布局中有一个线性布局,我想让按钮“更高”以适应线性布局的高度。

I tried adding padding, as you can see in the screenshot, the layout is 'taller' but the buttons are not. 我尝试添加填充,正如您在屏幕截图中看到的,布局是“更高”但按钮不是。 I tried 'fill_parent', 'match_parent' but it didn't make a difference. 我试过'fill_parent','match_parent',但没有什么区别。 How do I make the buttons expand in height? 如何使按钮扩展高度?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/timerLayout">

<Chronometer
    android:id="@+id/chronometer1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="48dp"
    android:text="@string/chronometer"
    android:textSize="50sp" />

<LinearLayout
    android:id="@+id/buttonLayout"
    android:orientation="horizontal"
    android:paddingLeft="4.0dp"
    android:paddingTop="50.0dp"
    android:paddingRight="4.0dp"
    android:paddingBottom="4.0dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

    <Button
        android:id="@+id/btnReset"
        android:layout_width="0.0dp"
        android:layout_height="fill_parent"
        android:drawableLeft="@drawable/ic_restore_white_24dp"
        android:drawableStart="@drawable/ic_restore_white_24dp"
        android:text="@string/pause_btn"
        android:layout_weight="1.5" />

    <Button
        android:id="@+id/btnStart"
        android:layout_width="0.0dp"
        android:layout_height="fill_parent"
        android:text="@string/start_btn"
        android:drawableLeft="@android:drawable/ic_media_play"
        android:drawableStart="@android:drawable/ic_media_play"
        android:layout_weight="1.5" />

    <Button
        android:id="@+id/btnSave"
        android:layout_width="0.0dp"
        android:layout_height="fill_parent"
        android:text="@string/save_btn"
        android:drawableLeft="@drawable/ic_save_white_24dp"
        android:drawableStart="@drawable/ic_save_white_24dp"
        android:layout_weight="1.0" />
</LinearLayout>

在此输入图像描述

your linearlayout says height:wrap_content so the child elements will takeup only as much space as specified. 你的linearlayout表示height:wrap_content所以子元素只会占用指定的空间。

Try giving either minHeight for linearlayout or simply remove linearlayout and in your buttons specifiy "alignparentbottom = true". 尝试给出linearHout的minHeight或简单地删除linearlayout,并在你的按钮中指定“alignparentbottom = true”。 For left-most button give alignparentStart = true. 对于最左边的按钮,给出alignparentStart = true。

Take a look at your xml layout file very closely 仔细看看你的xml布局文件

 <LinearLayout
    android:id="@+id/buttonLayout"
    android:orientation="horizontal"
    android:paddingLeft="4.0dp"

    android:paddingTop="50.0dp" //this guy 

    android:paddingRight="4.0dp"
    android:paddingBottom="4.0dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

the android:paddingTop is the space on the top of every child in your LinearLayout so if you remove it the buttons will fit. android:paddingTopLinearLayout中每个子LinearLayout顶部的空格,因此如果删除它,按钮就会适合。

The extra space you are seeing is from the padding values in your linear layout, and your buttons are already filling the parent linear layout. 您看到的额外空间来自线性布局中的填充值,并且您的按钮已经填充了父线性布局。 But your linear layout has specified the following. 但是您的线性布局指定了以下内容。

android:layout_height="wrap_content"

If you want to see buttons with a larger height, change the height value for your linear layout to something else like: 如果要查看高度较大的按钮,请将线性布局的高度值更改为:

android:layout_height="300dp"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM