아래 코드를 실행하면 LogCat에서 getParent가 다른 ViewGroup을 반환하고 FrameLayout (LinearLayout을 반환 함)을 확인할 수 있습니다. 일반적으로 나는 getParent가 framelayout을 반환 할 것이라고 기대합니다 ...getParent가 잘못된 ViewGroup을 반환합니다.
왜 이것이 발생하는지 알고 있습니까?
자바 :
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.actionbar_btn);
if (button.getParent() instanceof FrameLayout) {
Log.v("TAG", "parent was framelayout");
} else {
Log.v("TAG", "parent was no framelayout");
}
}
XML :
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/actionbar_home"
android:layout_width="33dp"
android:layout_height="32dp"
android:background="@drawable/ic_launcher"
/>
</FrameLayout>
.....
</LinearLayout>
</RelativeLayout>