私はリストビュー用にこのxmlレイアウトを持っています:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/menu"
android:orientation="vertical" android:background="#2f4f4f" android:layout_width="wrap_content" android:layout_height="fill_parent">
<ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#2f4f4f" android:cacheColorHint="#2f4f4f" android:scrollbars="none">
</ListView>
</LinearLayout>
線形レイアウトは、デフォルトで全画面幅を占有します。
プログラムで変更したい.次のようなものを作りたい:
しかし、linearlayout の幅を変更しても何も起こらず、画面全体の幅を占めています。
LayoutInflater inflater = LayoutInflater.from(this);
View menu = inflater.inflate(R.layout.xml_layout, null);
menu.setLayoutParams(new LayoutParams(20,LayoutParams.WRAP_CONTENT));
リストビューでレイアウト幅を次のようにハードコーディングした後:
<ListView
android:id="@+id/list"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#2f4f4f"
android:cacheColorHint="#2f4f4f"
android:scrollbars="none" >
</ListView>
私はこれを得る:
これを行う方法を提案してください。