вставить изображение в таблицу, не растягивая его Android - PullRequest
0 голосов
/ 26 апреля 2010

У меня возникают некоторые проблемы с получением изображений внутри таблицы. На самом деле, у каждого есть 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>

Ответы [ 2 ]

1 голос
/ 27 апреля 2010

Ваши изображения растягиваются из-за этой строки кода.

<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>

Попробуйте приведенный выше код в качестве примера.

0 голосов
/ 30 августа 2010

Альтернативное решение - добавить кнопку в макет и установить атрибут макета 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>
...