如何减少按钮高度以适应父布局

时间:2014-08-27 14:21:53

标签: android

是否可以降低按钮的高度以适应其父布局的高度?我不想指定任何特定的维度值。

我有一个简单的布局,TextView内有ButtonRelativeLayout。但是这个布局的高度太大了,因为它试图适应按钮的默认高度。

        <RelativeLayout
            android:layout_height="wrap_content" 
            android:layout_width="match_parent" 
            >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Reminder"
                />

            <Button
                android:id="@+id/btn_addremainder"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@null"
                android:text="+"
                android:layout_alignParentRight="true"
                />

        </RelativeLayout>

1 个答案:

答案 0 :(得分:1)

您的父布局设置为wrap_content,因此按钮设置为wrap_content。

而是将您的父布局(RelativeLayout)更改为特定高度 match_parent 。这样,按钮将适合父母,而不是适合按钮的父母。

简单地说:您需要一些具有特定高度的元素,因此其他元素可以相应缩放。

如果这不是您想要的,那么您需要做的就是删除按钮的minHeight:

android:minHeight="0dp"
相关问题