/ / Jak nie rozciągnąć obrazu przycisku w tabeli | ANDROID - android, obraz, przycisk, odcinek

Jak nie rozciągnąć obrazu przycisku w tabeli | ANDROID - android, obraz, przycisk, odcinek

Mam problem:

Mam tabelę z rzędem i dwiema komórkami. Rozłożyłem stolik na połowie ekranu. W każdej komórce znajduje się przycisk z własnym stylem przycisku (Android: tło). Każdy styl przycisku zawiera obraz. Problem polega jednak na tym, że obraz (przycisk) jest rozciągnięty. Nie wiem, co muszę zmienić, żeby obraz nie był już rozciągnięty.

Oto układ tabeli:

    <TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">

<Button
android:id="@+id/a"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/aa" />

</FrameLayout>

<FrameLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">

<Button
android:id="@+id/b"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:background="@drawable/bb" />

</FrameLayout>

</TableRow>
</TableLayout>

A oto styl przycisku:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/aa1"
android:state_pressed="true" />
<item android:drawable="@drawable/aa2" />
</selector>

Co muszę zmienić, aby obraz nie był rozciągnięty? Część obrazu powinna być dostępna i powinna być podzielona na połowę ekranu.

Dzięki za pomoc. To bardzo ważne.

Odpowiedzi:

0 dla odpowiedzi № 1

Wypróbuj ten układ: użyj a ImageButton zamiast Button i dodaj obraz android:src atrybut.

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

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">

<ImageButton
android:id="@+id/a"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:background="@android:color/transparent"
android:padding="15dp"
android:src="@mipmap/ic_launcher" />

</FrameLayout>

<FrameLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">

<ImageButton
android:id="@+id/b"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_marginBottom="5dp"
android:background="@android:color/transparent"
android:padding="15dp"
android:src="@mipmap/ic_launcher" />

</FrameLayout>

</TableRow>
</TableLayout>

Wydajność:

wprowadź opis obrazu tutaj