<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_content_fl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:text="click me111111111111111111" />
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="textview" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/show_toast_btn"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:text="click me2" />
</LinearLayout>
</FrameLayout>
执行:
for (int i = 0; i < my_content_fl.getChildCount(); i++) {
View childAt = my_content_fl.getChildAt(i);
String simpleName = childAt.getClass().getSimpleName();
Log.i("DD", simpleName + i);
}
输出:
05-04 03:10:34.853 8270-8270/com.csii.androidtest I/DD: RelativeLayout0
05-04 03:10:34.853 8270-8270/com.csii.androidtest I/DD: TextView1
05-04 03:10:34.853 8270-8270/com.csii.androidtest I/DD: LinearLayout2