Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 布局中包含的布局中的对象地址_Android_Xml_Android Layout - Fatal编程技术网

Android 布局中包含的布局中的对象地址

Android 布局中包含的布局中的对象地址,android,xml,android-layout,Android,Xml,Android Layout,我有一个main_layout.xml文件,其中包括两个自定义的_layout.xml文件,那么main_xml文件中内部对象的地址应该是什么 main_layout.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent"

我有一个main_layout.xml文件,其中包括两个自定义的_layout.xml文件,那么main_xml文件中内部对象的地址应该是什么

main_layout.xml

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:background="#882" >

    <include 
        layout="@layout/custom_layout"
        android:id="@+id/b1" />

    <include 
        layout="@layout/custom_layout"
        android:id="@+id/b2" />

</LinearLayout>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:background="#882">

    <Button 

        android:id="@+id/a1"
        android:layout_height="10px"
        android:layout_width="10px"
        android:text="first" />

    <Button

        android:id="@+id/a2"
        android:layout_height="10px"
        android:layout_width="10px"
        android:text="second" />

</LinearLayout>

custom_layout.xml

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:background="#882" >

    <include 
        layout="@layout/custom_layout"
        android:id="@+id/b1" />

    <include 
        layout="@layout/custom_layout"
        android:id="@+id/b2" />

</LinearLayout>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:background="#882">

    <Button 

        android:id="@+id/a1"
        android:layout_height="10px"
        android:layout_width="10px"
        android:text="first" />

    <Button

        android:id="@+id/a2"
        android:layout_height="10px"
        android:layout_width="10px"
        android:text="second" />

</LinearLayout>

所以在我的主布局中有四个按钮。在Android应用程序中,我需要特定的地址,比如R.id.a1,它给了我两个按钮的参考。请告诉我如何在第一次使用自定义_布局时获得第一个按钮。(我的try R.id.b1.a1失败) 提前谢谢

View view = findViewById(R.id.b1);

Button button = (Button)view.findViewById(R.id.a1);
通过这种方式,您可以参考特定的视图按钮