Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XML Android横幅_Android_Xml - Fatal编程技术网

XML Android横幅

XML Android横幅,android,xml,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" an

好的,我有这个代码,但当我启动应用程序时,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的警告“RelativeLayout或其父线性布局是无用的”

您收到的错误应该是警告而不是错误。正如它所说的那样。可以删除相对布局或线性布局。如果删除线性布局,则在相对布局中设置背景和其他信息。

您可以设置:
android:layout\u width
android:layout\u 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>

用以下内容替换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>


注意:不要忘记将高度
重量`添加到元素中

读取错误。如果你不懂,用谷歌搜索一下。如果仍然无法解决此问题,请在此处发布错误日志。没有必要强制搜索原因(有时有,但不要从那里开始:p)哪个错误?LogCat在哪里?