21

使用時fill_parentmaxWidth効果なし。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">
    <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical">
        <EditText android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:maxWidth="50dip"/>
    </LinearLayout>    
</LinearLayout>
4

3 に答える 3

30

この属性は(または非推奨の)maxWidthの幅には影響しません。これらは相互に排他的です。を使用する必要があります。match_parentfill_parentwrap_content

また、子が 1 つしかないレイアウトはおそらく削除できます。たとえば、現在のレイアウトを次のように単純化できます。

<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:maxWidth="50dip"/>
于 2012-11-10T19:44:41.627 に答える
8

画面ごとに異なるレイアウトを使用して、同じ効果を得ることができます。利用可能な幅を埋めたいEditTextが、480 dp を超えないようにしたいとします。次のようにレイアウトを定義します。

レイアウト/my_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"/>

layout-w480dp/my_layout.xml: (ここで修飾子として最大幅を選択します)

<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="480dp"
          android:layout_height="wrap_content"/>
于 2016-08-19T10:27:34.697 に答える