2013-06-25 176 views
0

layout.xml水平线性布局水平滚动视图内

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

<HorizontalScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:id="@+id/itemlist" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/itemlistbg" 
     android:gravity="center_vertical" 
     android:orientation="horizontal"/> 

</HorizontalScrollView> 

</LinearLayout> 

我加入孩子线性布局ID itemlist动态。如果项目太多,那么结果是好的。但是如果列表中有2个项目,则线性布局itemlist在最后留下空格。 this only happens on big screen devices

eclipse preview of xml http://i43.tinypic.com/ohvgg3.png

+0

图像是xml的eclipse预览。 –

回答

7

尝试像这样改变你的滚动视图。

<HorizontalScrollView 
    android:layout_width="fill_parent" 
    android:background="@drawable/itemlistbg" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:id="@+id/itemlist" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"   
     android:gravity="center_vertical" 
     android:orientation="horizontal"/> 

</HorizontalScrollView> 

我希望这会帮助你。

+0

谢谢你的回答....但如果在运行时有空列表,我将'itemlist'布局的可见性更改为'GONE'。这使得应用程序仅显示滚动视图的背景图像。 –

+0

为什么你不把你的可见性控制设置为'Horizo​​ntalScrollView'? – Gunaseelan

+0

我不想要这个。但现在我认为我必须这样做,没有选择。 恩,谢谢你的回答。 –

0

你试图使用android:layout_weight

+0

试过了,它说'Horizo​​ntalScrollView:layout_weight'中的布局参数无效。 –