Why nested layout is not accepted by Android?

时间:2016-10-20 19:39:03

标签: android android-layout

Have this nested layout structure:

<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="@android:color/black">

<ViewGroup
    android:layout_width="94dp"
    android:layout_height="54dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentEnd="true"
    android:id="@+id/view">

    <ImageView
        android:id="@+id/loggedInUserImageView"
        android:layout_width="66dp"
        android:layout_height="66dp"
        android:layout_alignParentTop="true"
        android:layout_alignEnd="@+id/view" />

</ViewGroup>
</RelativeLayout>

But get a rendering issue. Why? What is the problem?

3 个答案:

答案 0 :(得分:0)

You cannot have a ViewGroup child in this case. Because you don't have attribute/property for positioning of chil view. So it will throw an error While Rendering. You have all the options of using Different Layouts provided by android, as they are also extended from ViewGroup only.

If you want to Use ViewGroup better extend it and then use the extended class.

Hope this helps you understand.

答案 1 :(得分:0)

You cannot use ViewGroup inside an XML file, use LinearLayout, RelativeLayout, etc.. or create a custom ViewGroup, by extending it.

答案 2 :(得分:0)

You are trying to instantiate an abstract class(ViewGroup). Create your custom view which extends ViewGroup, after that you are eligible to instantiate you custom view.

相关问题