1、LayoutInflater flater = LayoutInflater.from(this);
View view=flater.inflate(R.layout.activity_main, null);
System.out.println(view.getParent()+" 777777777");
System.out.println(view.getId()+" 66666666666666666");
2、View findViewById = findViewById(R.id.kk);
System.out.println(findViewById.getId());
System.out.println(findViewById.getParent());
输出:
1:
null 777777777
2131230720 66666666666666666
2:
2131230720
android.widget.FrameLayout{b3d6c1c0 V.E..... ......I. 0,0-0,0 #1020002 android:id/content}
我想问一下1、2两种方法getId都是一样的,为什么getParent就不一样了呢?
这个是布局文件
<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/kk"
android:id="@+id/as"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />