2013-07-29 200 views
0

如何最小化圖像視圖左側和右側的間距?我的xml文件在圖像的左側和右側顯示了很多空間。我的屏幕看起來是這樣的:如何減少我的屏幕左側和右側的空白?

image

,我想讓它像這樣:

image2

如何減少間距上的圖像的左側和右側?

<LinearLayout 

android:layout_width="match_parent" 
android:layout_height="match_parent" 

android:gravity="center" 
android:orientation="horizontal" > 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 

    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/img1" 
     android:layout_width="70dp" 
     android:layout_height="80dp" 
     android:contentDescription="@null" 
     android:background="@drawable/imagebgborder" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/txt1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="5dp" 
     android:textStyle="bold" 
     android:contentDescription="@null" 
     android:text="@string/hello_world" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="5dp" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/img2" 
     android:layout_width="70dp" 
     android:layout_height="80dp" 
     android:contentDescription="@null" 
     android:background="@drawable/imagebgborder" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/txt2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="5dp" 
     android:contentDescription="@null" 
     android:text="@string/hello_world" /> 
</LinearLayout> 

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

    <ImageView 
     android:id="@+id/img3" 

     android:layout_width="70dp" 
     android:layout_height="80dp" 
     android:contentDescription="@null" 
     android:background="@drawable/imagebgborder" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/txt3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="5dp" 
     android:contentDescription="@null" 
     android:text="@string/hello_world" /> 
</LinearLayout> 
</LinearLayout> 

回答

0

我已經做了這樣的事情,併成功地使用TableLayout而不是主要內容(您的3項)。 http://developer.android.com/reference/android/widget/TableLayout.html

更新代碼:

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

    <!-- NEW LINEAR LAYOUT --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:orientation="horizontal" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp" > 

     <!-- Your individual items go here --> 

     <TableLayout 
      android:id="@+id/tableLayoutPlacard" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:gravity="center_vertical" > 

      <TableRow 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:gravity="center_horizontal" 
       android:paddingLeft="5dp" 
       android:paddingRight="5dp" > 

       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:orientation="vertical" > 

        <ImageView 
         android:id="@+id/img1" 
         android:layout_width="70dp" 
         android:layout_height="80dp" 
         android:background="#FFFFFF" 
         android:contentDescription="@null" 
         android:src="@drawable/ic_launcher" /> 

        <TextView 
         android:id="@+id/txt1" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_marginTop="5dp" 
         android:background="#FFFFFF" 
         android:contentDescription="@null" 
         android:gravity="center" 
         android:text="ITEM 1" 
         android:textStyle="bold" /> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:orientation="vertical" > 

        <ImageView 
         android:id="@+id/img1" 
         android:layout_width="70dp" 
         android:layout_height="80dp" 
         android:background="#FFFFFF" 
         android:contentDescription="@null" 
         android:src="@drawable/ic_launcher" /> 

        <TextView 
         android:id="@+id/txt1" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_marginTop="5dp" 
         android:background="#FFFFFF" 
         android:contentDescription="@null" 
         android:gravity="center" 
         android:text="ITEM 2" 
         android:textStyle="bold" /> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:orientation="vertical" > 

        <ImageView 
         android:id="@+id/img1" 
         android:layout_width="70dp" 
         android:layout_height="80dp" 
         android:background="#FFFFFF" 
         android:contentDescription="@null" 
         android:src="@drawable/ic_launcher" /> 

        <TextView 
         android:id="@+id/txt1" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_marginTop="5dp" 
         android:background="#FFFFFF" 
         android:contentDescription="@null" 
         android:gravity="center" 
         android:text="ITEM 3" 
         android:textStyle="bold" /> 
       </LinearLayout> 
      </TableRow> 
     </TableLayout> 
    </LinearLayout> 

</LinearLayout> 
+0

代碼顯示垂直 – user2589245

+0

屏幕看起來這艾克現在http://imgur.com/mD5K2wP – user2589245

+0

我不好,我工作的另一個項目和沒」 t測試了這一點。嘗試使用TableLayout的上述更新。 –