layoutInflaterを使用してレイアウトを別のレイアウトに配置したいと思います。
main_layout.xmlファイルは次のとおりです。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/ads_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<RelativeLayout
android:id="@+id/host_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/navigation_buttons_layout"
android:layout_alignParentLeft="true"
android:layout_below="@+id/ads_image_view" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/navigation_buttons_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button" />
</RelativeLayout>
これがvitrin_layout.xmlファイルです。
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0000"
android:text="smallred" />
そして最後に、私のメインアクティビティのonCreateメソッド:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
ViewGroup parent = (ViewGroup) findViewById(R.id.host_layout);
View view = LayoutInflater.from(getBaseContext()).inflate(
R.layout.vitrin_layout, null);
parent.addView(view, LayoutParams.FILL_PARENT);
setTitle(getString(R.string.title_activity_vitrin));
}
問題は、vitrin_layoutがその親(host_layout)に適合しないことです。可能な限りfill_parentを設定しましたが!
理由がわかりません。
編集:本当に申し訳ありませんが、間違ったvitrin_layoutファイルを貼り付けたので、修正しました。