【发布时间】:2015-07-27 01:55:08
【问题描述】:
我想要一些右侧带有按钮的 EditText。现在我只是让 Edittexts 用 0dp 技巧填充父级。如果我添加按钮,EditText 的高度将随着 wrap_content 缩小。如果我做 match_parent 一个 EditText 填满整个屏幕。
RelativeLayout 不起作用,因为您无法像 LinearLayout 那样使其匹配父级。
我想获得屏幕高度,然后将布局高度设置为 1/7(因为我有 7 个 EditText)。合理吗?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText android:id="@+id/box_0"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_task"
android:saveEnabled="true"
android:inputType="textCapSentences"
android:maxLength="32"
android:padding="10dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:layout_gravity="end"/>
<!--red-->
</LinearLayout>
<EditText android:id="@+id/box_1"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:saveEnabled="true"
android:inputType="textCapSentences"
android:maxLength="32"
android:padding="10dp"/>
<EditText android:id="@+id/box_2"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:saveEnabled="true"
android:inputType="textCapSentences"
android:maxLength="32"
android:padding="10dp"/>
<EditText android:id="@+id/box_3"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:saveEnabled="true"
android:inputType="textCapSentences"
android:maxLength="32"
android:padding="10dp"/>
<EditText android:id="@+id/box_4"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:saveEnabled="true"
android:inputType="textCapSentences"
android:maxLength="32"
android:padding="10dp"/>
<EditText android:id="@+id/box_5"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:saveEnabled="true"
android:inputType="textCapSentences"
android:maxLength="32"
android:padding="10dp"/>
<EditText android:id="@+id/box_6"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:saveEnabled="true"
android:inputType="textCapSentences"
android:maxLength="32"
android:padding="10dp"/>
</LinearLayout>
我只在第一个 EditText 中做了双 LinearLayout。
http://i.imgur.com/t4hN6nO.jpg
看看第二个比其他的要大来补偿,而第一个更小?
【问题讨论】:
-
你想要哪种布局?
标签: android android-layout android-edittext android-linearlayout android-button