我有一个 EditText
和一个 Button
在同一水平线上彼此相邻设置。它看起来很棒,除了当用户输入大量文本时,EditText
被调整大小,Button
被压扁。
我将 EditText
和 Button
都设置为 layout_width="wrap_content"
。 "fill_parent"
弄乱了布局,如果我不需要,我不想使用绝对尺寸 - 现在它在横向和纵向看起来都很棒,我只是不不希望 EditText
调整大小。
我的布局:
<TableLayout
android:id="@+id/homelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow>
<TextView
android:id="@+id/labelartist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Find artists:" />
</TableRow>
<TableRow>
<EditText
android:id="@+id/entryartist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="6"
android:background="@android:drawable/editbox_background"
android:editable="true"
android:padding="5px"
android:singleLine="true" />
<Button
android:id="@+id/okartist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:text="Search" />
</TableRow>
</TableLayout>
最佳答案
供 EditText 使用
android:layout_width="0dp" - not required but preferred.
android:layout_weight="1"
并且对于 Button 不要指定 android:layout_weight
关于android - 如何防止 EditText 在用户键入时自行调整大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1408781/