Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.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
Android 布局定义&引用;您必须提供版面宽度属性;_Android_Android Layout - Fatal编程技术网

Android 布局定义&引用;您必须提供版面宽度属性;

Android 布局定义&引用;您必须提供版面宽度属性;,android,android-layout,Android,Android Layout,我正在开发一个小的android应用程序,我的布局有问题,我一直试图在我的xml中找到错误,但我找不到它 我得到的错误是“您必须提供布局宽度属性”,但我这样做了,它仍然不起作用 这是我的XML文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fil

我正在开发一个小的android应用程序,我的布局有问题,我一直试图在我的xml中找到错误,但我找不到它

我得到的错误是“您必须提供布局宽度属性”,但我这样做了,它仍然不起作用

这是我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="100" >

    <TextView android:id="@+id/nombreEvento"
        android:layout_height="fill_parent"
        android:layout_weight="70"
    />

    <TextView android:id="@+id/moneda"
        android:layout_height="fill_parent"
        android:layout_weight="10"
    />

    <TextView android:id="@+id/totalEvento"
        android:layout_height="wrap_content"
        android:layout_weight="20"
    />
    </LinearLayout>

<TextView android:id="@+id/fecha"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>

</LinearLayout>

您需要指定视图的宽度和高度。这是必须的。对于textview,您只需设置高度和重量。加

android:layout_width="0dip"

不,您的所有文本视图都具有布局高度和布局重量,而不是布局高度和布局宽度(可能还有布局重量)。试试这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="100" >

    <TextView android:id="@+id/nombreEvento"
        android:layout_height="fill_parent"
        android:layout_width="0dp"
        android:layout_weight="70"
    />

    <TextView android:id="@+id/moneda"
        android:layout_height="fill_parent"
        android:layout_width="0dp"
        android:layout_weight="10"
    />

    <TextView android:id="@+id/totalEvento"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="20"
    />
    </LinearLayout>

<TextView android:id="@+id/fecha"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>

</LinearLayout>


尝试将android:layout\u width=“wrap\u content”添加到没有的文本视图中。

在我的例子中,我忘了将layout\u width属性添加到TableLayout中


这有点让人困惑,因为TableRow是TableLayout的子级,它不需要布局宽度,所以我在本期中运行

我想你没有把
dp
放在宽度大小之后。为什么你的代码可能不起作用。 ex
android:layout\u weight=“20”

在我的例子中,
android:layout\u width=“@dimen/abc\u action\u bar\u progress\u bar\u size”
已设置,但
@dimen/abc\u action\u bar\u progress\u bar\u size
是私有的。因此,它并没有抱怨无法访问它,而是悄悄地删除了它,以便在以后抱怨它丢失了。

在我的例子中,当您使用属性但忘记将属性映射到样式时,也会出现相同的错误,当我重建Project&Invalidate cache并重新启动我的android Studio IDE时,它起了作用,我以前也一直使用它,但通常在对多个项目使用权重时,您希望进行0dp,因为大多数情况下,您希望宽度达到一定的比例,而不是让视图在宽度上包装内容,然后使用权重填充剩余空间。作为0dip的替代方法,我在应用权重时通常使用填充父项/匹配父项,它似乎也这样做。但这取决于OP的决定。我也试过,但我有问题。它通常是有效的,但偶尔(但并非始终如一)奇怪的事情会发生,因为它会变得比你预期的更大。我在将内容从屏幕上删除时遇到了问题。有什么区别吗?@AlikElzin kilaka嵌套文本视图具有布局权重。。。也应该有布局宽度。我有一个类似的问题。如果要从XML扩展布局,并且该XML的根是TableRow,则必须指定TableRow的宽度。很好,这是我的修复方法。