「Android/レイアウト/レイアウトファイルをjavaで取得」の版間の差分
提供: 初心者エンジニアの簡易メモ
行1: | 行1: | ||
+ | res/layout/main.xml | ||
+ | <pre> | ||
+ | <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> | ||
+ | </pre> | ||
+ | |||
res/layout/video_item.xml | res/layout/video_item.xml | ||
<pre> | <pre> | ||
行6: | 行23: | ||
android:gravity="center_horizontal" | android:gravity="center_horizontal" | ||
android:orientation="vertical"> | android:orientation="vertical"> | ||
− | |||
<ImageView | <ImageView | ||
android:id="@+id/iconImage" | android:id="@+id/iconImage" |
2019年3月26日 (火) 16:39時点における版
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