【问题标题】:ImageViews taking a lot space than its need (XML)ImageViews 占用的空间超出了它的需要 (XML)
【发布时间】:2014-12-27 21:14:50
【问题描述】:

我想像安卓市场一样在HorizontalScrollView 中并排显示ImageView。我在 LinearLayout 内的 ImageView 占用空间时遇到问题,这就是我得到的:由长 uncontrolled 空格分隔的图像。

编辑:ScrollView 工作正常,只是想最小化图像之间的距离并并排显示图像。

我希望它是这样的:

这里是该行的xml 代码:

 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical" >

    <TableRow
    android:id="@+id/tableRow2"
    android:layout_width="wrap_content"
    android:layout_height="250dp"
     android:background="#afafafaf" >

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

              <LinearLayout android:id="@+id/_linearLayout"  
               android:layout_width="wrap_content"  
               android:layout_height="wrap_content"  
               android:orientation="horizontal"
               android:gravity="center">  

                 <ImageView android:id="@+id/_image"   
                   android:layout_width="wrap_content"   
                   android:layout_height="wrap_content"
                   android:layout_marginTop="10dp"
                   android:background="#000000"
                   android:src="@drawable/icon_2"
                                            />   
                  <ImageView android:id="@+id/_image"   
                  android:layout_width="wrap_content"   
                  android:layout_height="wrap_content"
                  android:layout_marginTop="10dp"
                  android:background="#000000"
                  android:src="@drawable/icon_2"
                                            />   

             </LinearLayout>  

       </HorizontalScrollView>  


  </TableRow>

 <TableRow> </TableRow> <!-- ........ other table rows for other things -->

【问题讨论】:

  • 我认为你的表格行和滚动视图宽度应该设置为fill_parent。现在的情况,您的滚动视图可能无法扩展到您想要的宽度。
  • 先生,滚动视图扩展工作正常,我希望图像之间的空间最小化

标签: android xml imageview android-linearlayout


【解决方案1】:

TableLayout 的子级不能指定layout_width 属性,它始终是match_parent,您可以将视图添加到TableLayout,在这种情况下,该视图将跨越整个宽度。此外,除非孩子是View,否则TableRow 的高度总是wrap_content。所以删除TableRow 元素,一切都应该没问题。如果删除 TableRow 元素,请确保不要将 HorizontalScrollViewlayout_width 指定为 wrap_content。 而且,TableRow 仅用于 TableLayout 内的子级,为什么要将 TableRow 嵌套在 LinearLayout 内。

【讨论】:

  • 考虑改用ViewPager
猜你喜欢
  • 2017-03-01
  • 1970-01-01
  • 2020-10-11
  • 2015-09-05
  • 2020-10-29
  • 2014-06-06
  • 2014-08-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多