0

テーブルレイアウト内で写真を取得するのに問題があります...実際には、それぞれに2つの列があり、テーブルのセルに写真を入れると、完全に引き伸ばされて不均衡になります...作成方法が見つかりませんセル内の元の状態のままにして、残りのスペースをたとえば白い背景で埋めます.... XMLはそのようなものです:

<TableLayout android:layout_width="fill_parent" android:stretchColumns="*"
android:layout_marginLeft="3dip" android:layout_marginRight="10dip"
android:layout_height="wrap_content">

<TableRow android:layout_marginBottom="10dip">
<TextView android:id="@+id/tv01" android:text="text1"
 android:textSize="14sp" android:layout_margin="1dip"
 android:layout_height="wrap_content" android:textColor="@color/bleuLink"
 android:layout_width="wrap_content" android:layout_weight="1"
 android:background="@color/background"></TextView>

 <Button android:id="@+id/add" android:background="@drawable/addressbook"
  android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>
 <Button android:id="@+id/call" android:background="@drawable/greenphone"
  android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>

4

2 に答える 2

1

このコード行が原因で、画像が伸びています。

<TableLayout android:layout_width="fill_parent" android:stretchColumns="*" />

テーブルに親を埋めるように指示してから、伸縮可能な列をすべてに設定するため、レイアウトでは子が必要なスペースを埋めるように強制されます。ストレッチ可能な列属性を削除するか、ストレッチする列のインデックスのコンマ区切りリストに設定します。

   <TableLayout android:layout_width="fill_parent"
        android:stretchColumns="0, 2" android:layout_marginLeft="3dip"
        android:layout_marginRight="10dip" android:layout_height="wrap_content">
        <TableRow android:layout_marginBottom="10dip">
            <TextView android:id="@+id/tv01" android:text="text1"
                android:textSize="14sp" android:layout_margin="1dip"
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" android:layout_weight="1"></TextView>

            <Button android:id="@+id/add" android:background="@drawable/icon"
                android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>
            <Button android:id="@+id/call" android:background="@drawable/icon"
                android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>
        </TableRow>
    </TableLayout>

上記のコードを例として試してください。

于 2010-04-26T21:47:51.177 に答える
0

別の解決策は、ボタンをレイアウトに追加し、レイアウト属性 android:layout_height="wrap_content" を設定することです。

<TableLayout android:layout_width="fill_parent"
    android:stretchColumns="*" android:layout_height="wrap_content">
    <TableRow>
        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:gravity="center">
            <TextView android:id="@+id/tv01" android:text="text1"
                android:textSize="14sp" android:layout_margin="1dip"
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" android:layout_weight="1">
            </TextView>
        </LinearLayout>

        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:gravity="center">
            <Button android:id="@+id/add" android:background="@drawable/icon"
                android:layout_height="wrap_content" android:layout_width="wrap_content"> 
            </Button>
        </LinearLayout>

        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:gravity="center">
            <Button android:id="@+id/call" android:background="@drawable/icon"
                android:layout_height="wrap_content" android:layout_width="wrap_content">
            </Button>
        </LinearLayout>
    </TableRow>
</TableLayout>
于 2010-08-30T03:28:48.093 に答える