Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.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
Java 如何获取access RelativeLayout作为变量?_Java_Android_Android Layout_Android Relativelayout - Fatal编程技术网

Java 如何获取access RelativeLayout作为变量?

Java 如何获取access RelativeLayout作为变量?,java,android,android-layout,android-relativelayout,Java,Android,Android Layout,Android Relativelayout,我不知道如何以编程方式访问RelativeLayout,以便调用方法,例如RelativeLayout.getChildCount()在处理程序中 编辑-好的,如果我想获得RelativeLayout中的视图总数,我会调用什么函数?在文件夹res/layout中,我假设您的布局名为layout.xml 确保你的亲戚有android:id段 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

我不知道如何以编程方式访问RelativeLayout,以便调用方法,例如
RelativeLayout.getChildCount()在处理程序中


编辑-好的,如果我想获得RelativeLayout中的视图总数,我会调用什么函数?

在文件夹res/layout中,我假设您的布局名为layout.xml

  • 确保你的亲戚有android:id段

    <RelativeLayout 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:id="@+id/myRelativeLayout" > //the id name can be acsessed in activity
    
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/hello_world" />
    
    </RelativeLayout>
    

  • 在文件夹res/layout中,我假设您的布局名为layout.xml

  • 确保你的亲戚有android:id段

    <RelativeLayout 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:id="@+id/myRelativeLayout" > //the id name can be acsessed in activity
    
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/hello_world" />
    
    </RelativeLayout>
    

  • 请澄清您的问题是的,但这里的问题是我想获得在XML相对布局中定义的视图数量,如何将其链接到java表单?请澄清您的问题是的,但这里的问题是我想获得在XML相对布局中定义的视图数量,如何将其链接到java表单?