Android-Android.widget.ImageView无法转换为Android.view.ViewGroup



试图在模拟披萨表单上获得披萨标志的背景。

出于某种原因,我总是犯错误。

这是布局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>

我不知道为什么我总是犯这个错误。我试着将图像视图包装在框架布局中,但不起作用。

感谢您提供的任何帮助!

问题是</ImageView>。由于ImageView不能承载视图,所以你不能将它们包裹起来。去掉</ImageView>,从更改

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

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

/>将关闭ImageView的标签

您不能在ImageView标记中放入任何视图。

如果你想设置这个标志,试着像这样使用linearLayout的背景。

<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>

相关内容

最新更新