2014-12-27 68 views
0

我想在HorizontalScrollView中像ImageView一樣顯示android市場。我遇到了ImageView裏面的空間問題LinearLayout,在這裏我得到:圖像分開很長不受控空間。ImageViews佔用了大量的空間(XML)

編輯:ScrollView工作正常,只是想盡量減少圖像之間的距離和並排顯示圖像。

enter image description here enter image description here enter image description here

我希望它是這樣的:

enter image description here

這裏此行的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 --> 
+0

我認爲你的表格行和滾動視圖寬度應該設置爲'fill_parent'。現在的方式是,您的滾動視圖可能無法展開到所需的寬度。 – mkasberg

+0

先生,滾動視圖擴展工作正常,我希望圖像之間的空間最小化 – Yousif

回答

1

一個的孩子不能指定layout_width屬性,總是match_parent,您可以添加一個視圖到TableLayout,在這種情況下,該視圖將跨越整個寬度。另外,除非孩子是ViewTableRow的身高始終是wrap_content。所以刪除TableRow元素那裏一切都應該罰款。如果您刪除了TableRow元素,請務必不要指定layout_widthHorizontalScrollViewwrap_content。 而且,TableRow只能用於TableLayout以內的孩子,爲什麼要在LinearLayout內嵌套TableRow

+0

我編輯了xml代碼並添加了一些圖像 – Yousif

+0

請考慮使用'ViewPager' – Biu