XML Android Banner

时间:2014-02-28 17:34:04

标签: android xml

好的,所以我有这个代码,但是当我启动应用程序时,我在LogCat中收到错误:

<LinearLayout 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:orientation="vertical"
    android:background="@drawable/menubackground">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:src="@drawable/gameicon"
            android:contentDescription="@string/icon"/>

        <TextView 
            android:layout_centerHorizontal="true"
            android:layout_alignParentTop="true"
            android:text="@string/game_title"
            android:textSize="@dimen/game_title_size"
            android:textColor="@color/golden_yellow"/>

        <ImageView 
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:src="@drawable/gameicon"
            android:contentDescription="@string/icon"/>
    </RelativeLayout>
</LinearLayout>

如果我删除2x图像视图和文本视图,它会启动,因此可能存在问题。 而且我也在RelativeLayout上发出警告“The RelativeLayout或其父级LinearLayout无用”

3 个答案:

答案 0 :(得分:0)

您获得的错误应该是警告而不是错误。正如它所述。您可以删除相对布局或删除线性布局。如果删除线性布局,请改为设置相对布局中的背景和其他信息。

答案 1 :(得分:0)

您为视图选择了android:layout_widthandroid:layout_height。 例如:

<LinearLayout 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:orientation="vertical">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/ic_file" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true" />

    </RelativeLayout>
</LinearLayout>

答案 2 :(得分:0)

用以下代码替换您的XML代码:

 <LinearLayout 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:orientation="vertical" >

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="Text"
        android:textSize="18sp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />
</RelativeLayout>

注意:对你的元素t ever forget to add the高度and the权重