2011-02-15 39 views
0

我在我的應用中有兩個ImageView s,一個TextView和一個Gallery,並且希望我的佈局如下所示。使用TableLayout和圖庫在Android中設計佈局

............................................-. 
<ImageView>|  <TextView>  |<ImageView>| 
.............................................. 
|           | 
|     Gallery     | 
|           | 
|............................................| 

我有一個表的佈局和幾乎拿到屈尊如上所示不同之處在於當文本長度小的ImageView在屏幕的右端保持移動。我希望屏幕左側和右側的ImageView的位置固定,而不考慮文本的大小。

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

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"> 

     <TableRow> 
       <ImageView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/imageL" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" 
        android:minHeight="30px" 
        android:minWidth="30px" /> 

       <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/title" 
        android:paddingLeft="10px" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="3" 
        android:layout_gravity="center" 
        android:minHeight="30px" 
        android:minWidth="30px" /> 

       <ImageView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/imageR" 
        android:paddingLeft="10px" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" 
        android:minHeight="30px" 
        android:minWidth="30px" /> 
      </TableRow> 
    </TableLayout> 

    <Gallery xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/gallery" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

回答

0

就是這樣。如果你想使靜態的寬度和高度的img你可以將其設置在android系統:layout_width和android:layout_height

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 
    <ImageView 
    android:id="@+id/firstImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:src="@drawable/icon" 
    /> 
    <TextView 
    android:id="@+id/someText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@+id/secondImage" 
    android:layout_toRightOf="@+id/firstImage" 
    android:text="some mega text." 
    android:gravity="center_horizontal" 
    /> 
    <ImageView 
    android:id="@+id/secondImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/icon" 
    /> 

</RelativeLayout> 
+0

謝謝。有效。 – Vinoth 2011-02-15 14:46:24

0

使用相同的權重爲所有三個項目,問題應該可以解決。

android:layout_weight="1" 

所有3個將佔據相同的面積。

0

添加到您的TableLayout標籤:

android:shrinkcolumns="0,2" android:stretchColumns="1" 

此外,您可能要更改layout_width而不是FILL_PARENT,因爲這將允許中間柱伸展。