Android/レイアウト/レイアウトファイルをjavaで取得
提供: 初心者エンジニアの簡易メモ
res/layout/main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/simple_video_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
res/layout/video_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/iconImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
hogehoge.java
import android.view.LayoutInflater; LayoutInflater inflater = LayoutInflater.from(this); LinearLayout itemLayout = (LinearLayout)inflater.inflate(R.layout.video_item, null); // id取得 Button button = (Button)itemLayout.findViewById(R.id.button1);
参考:http://inujirushi123.blog.fc2.com/blog-entry-27.html
参考:https://developer.android.com/reference/android/view/LayoutInflater
