Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.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_Layout - Fatal编程技术网

Android 安卓布局:权重不小于';不要在设备上工作

Android 安卓布局:权重不小于';不要在设备上工作,android,layout,Android,Layout,对于ListActivity行,我得到了两种不同的行为。Eclipse图形布局显示了正确的行为,但在运行时,设备上的Layout:weight似乎无法正常工作,Textview的大小调整为最小宽度,具体取决于text属性 这就是我设置布局的方式 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" andro

对于ListActivity行,我得到了两种不同的行为。Eclipse图形布局显示了正确的行为,但在运行时,设备上的Layout:weight似乎无法正常工作,Textview的大小调整为最小宽度,具体取决于text属性

这就是我设置布局的方式

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="60dp" 
    android:background="@color/defaultBg" 
    android:orientation="horizontal">

   <ImageButton
        android:id="@+id/myButton"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_marginLeft="5dp"
        android:layout_weight="2" 
        android:src="@drawable/ic_launcher"/>

   <TextView
           android:id="@+id/myText"
           android:layout_width="0dp"
           android:layout_height="fill_parent"
           android:layout_margin="5dp"
           android:background="#2288EE"
           android:layout_weight="6" android:text="Hello" android:textColor="@android:color/white"/>
</LinearLayout>

编辑:我刚刚发现LinearLayout没有填充列表行宽度。我仍在努力寻找解决方法


非常感谢您的任何帮助。

在您的
线性布局中
put
android:weightSum=“8”
。它应该可以做到这一点,在我的设备上运行良好。

尝试将android:scaleType=“fitCenter”添加到您的ImageButton中。如果我没有弄错的话,您的源代码Drawable太大,因此ImageButton占用了太多的水平空间。

我自己解决了这个问题。问题不在上面发布的表行布局中。问题出在android上:父ListView的布局宽度设置为“wrap\u content”,而不是“fill\u parent”


感谢每一位贡献自己的人

使用
fill\u parent
更改
textView和ImageView的宽度这并不能解决问题。。相反,我读了很多文章,其中建议在使用layout:weight属性时将layout:width设置为“0dp”。@mauronnis您的问题是否解决了?没有Dipak。我只添加了一个更新。无论如何,我想我必须设置列表行来扩展整个宽度。我只是夸大了行布局。谢谢你的帮助,但这并不能解决我的问题。请发布整个布局。你看到的是整个布局。我只是在模拟器上测试应用程序,得到了与设备上相同的意外布局。此外,在代码中,我禁用了gui组件上的所有操作。没有TA,正如我所写的,问题在于TextView在其右侧留下了未使用的空间。ImageButton取而代之的是预期的空格。实际上这是正确的,请尝试将其标记为正确答案=)