我想设置一个编辑框的最大宽度。所以我创建了这个小布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxWidth="150dp" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout>
但是它不起作用,无论如何,盒子可能超过150 dp。 android:maxWidth="150dp"
中的EditText
将得到相同的结果。我已经读过(maxWidth doesn't work with fill_parent),将最大和最小宽度都设置为相同的大小应该可以解决它:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:maxWidth="50dp"
android:minWidth="50dp" />
但不是。
我在这里找到了解决我问题的方法:Setting a maximum width on a ViewGroup这很棒。但是由于我的原因,我想maxWidth
属性在这里。应该如何使用?或对此有任何文档吗?我花了几个小时解决这个问题,但仍然不了解如何使用这个简单的属性。