Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - android.widget.ImageView cannot be cast to android.view.ViewGroup

Trying to get a background of a pizza logo on a mock pizza form.

For some reason, I keep getting an error.

Here is the layout xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".Short_Williams_Assignment3">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="@string/photo"
    android:id="@+id/pizzaLogo"
    android:src="@drawable/pizza">
<LinearLayout>
 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/title_label"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Extra Large"
        android:id="@+id/radioButton4"
        android:checked="false" />

</LinearLayout>
</ImageView>
</FrameLayout>

I'm not sure why I keep getting this error. I tried wrapping the image view inside of a frame layout, but it doesnt work.

Thanks for any help you may provide!

like image 453
Chelly S Avatar asked Oct 28 '15 16:10

Chelly S


2 Answers

the problem is </ImageView>. Since ImageView can't host views you can't wrap them around it. Get rid of </ImageView> and change from

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="@string/photo"
    android:id="@+id/pizzaLogo"
    android:src="@drawable/pizza">

to

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="@string/photo"
    android:id="@+id/pizzaLogo"
    android:src="@drawable/pizza" />

/> will close the ImageView's tag

like image 111
Blackbelt Avatar answered Oct 29 '22 20:10

Blackbelt


You can't put any View inside ImageView Tag .

if you want to set that logo try using background for your linearLayout like this .

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/pizza">
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="@string/title_label"
    android:id="@+id/textView"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

    <RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Extra Large"
    android:id="@+id/radioButton4"
    android:checked="false" />

</LinearLayout>
like image 31
behrooz Avatar answered Oct 29 '22 18:10

behrooz