2012-12-06 37 views
0

我得到了两个不同行为的ListActivity行。 Eclipse图形布局显示正确的行为,但在运行时,在设备上,布局:重量似乎无法正常工作,并且文本视图的大小调整为最小宽度,具体取决于文本属性。Android布局:重量在设备上不起作用

这是我如何设置布局。

<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不填充listRow宽度。我仍然试图找到如何解决

任何帮助将不胜感激。

+0

用'fill_parent'改变'textView和ImageView'的宽度 –

+0

这并没有解决问题..相反,我读了很多帖子,建议在设置layout时使用layout:width属性设置宽度为'0dp' 。 –

+0

@MauroNonnis你的问题解决了吗? –

回答

2

我自己修复了这个问题。问题不在上面显示的表格行布局中。问题出在父列表视图的android:layout_width中,它被设置为'wrap_content'而不是'fill_parent'。

感谢所有提供他的贡献的人!

+0

的确如此,请尝试将其标记为正确答案,请=) –

0

在你的LinearLayoutandroid:weightSum="8"。它应该做的伎俩,我的设备工作正常。

+0

感谢您的帮助,但这并不能解决我的问题 –

+0

请发布整个布局。 –

+0

你看到的是整个布局。我只是在模拟器上测试应用程序,并得到与设备上相同的意外布局。此外,在代码中,我禁用了gui组件的所有操作。 –

0

尝试添加android:scaleType =“fitCenter”到您的ImageButton。如果我没有弄错,你的Source Drawable太大了,所以ImageButton会占用太多的水平空间。

+0

没有Tas,因为我写的问题是关于TextView,它留下了未使用的空间在其右侧。 ImageButton代替预期的空间。 –