次のようなxmlレイアウトファイルを取得しました。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/tabBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#474747"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/BtnSlide"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:src="@drawable/lin" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="SteriaFIT Mobile"
android:gravity="center"
android:paddingLeft="12dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<RelativeLayout
android:background="#41413F"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<LinearLayout
android:id="@+id/some_layout_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
<View
android:layout_below="@id/some_layout_item"
android:layout_width="fill_parent"
android:layout_height="5dip"
android:background="@drawable/drop_shadow">
</View>
<ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content"
android:background="#FFFFFF" android:cacheColorHint="#FFFFFF">
</ListView>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To Next Activity" />
tabBar
このファイルから別の xml レイアウト ファイルにレイアウトを取得したいだけです@+id
。この方法の後に含めることでこれを行います。
<include android:id="@+id/tabBar" layout="@layout/horz_scroll_app" />
しかし、このコード行にはレイアウトファイル全体が含まれているように思えますか?
編集
Button
このメソッドはid とともに私にも与えることに言及する必要がありますbutton1
編集2
tabBar
わかりましたので、次のように新しいレイアウト ファイルの中に入れた後:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#474747"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/BtnSlide"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:src="@drawable/lin" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="SteriaFIT Mobile"
android:gravity="center"
android:paddingLeft="12dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
これを元のxmlレイアウトに次のように含めました:
<include layout="@layout/tab_bar" android:id="@+id/tabBar" />
レイアウト内に何も登録できないようOnClickListener
です。私がやろうとしたこと:ImageButton
tabBar
View app = inflater.inflate(R.layout.tab_bar, null);
ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar);
btnSlide = (ImageButton) tabBar.findViewById(R.id.BtnSlide);
btnSlide.setOnClickListener(new ClickListenerForScrolling(scrollView, menu));
誰かヒントをくれませんか=