Размер кнопки с изображением
Можете ли вы помочь мне решить мою маленькую проблему??? У меня есть стол из кнопок. В моем XML-файле кнопки имеют этот код
<Button
android:id="@+id/b_0xa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_0xa" />
В моем main.class у меня есть эта строка:
b_0xb.setBackgroundResource(R.drawable.green);
потому что я хочу изменить фон кнопки после того, как я нажал на нее. Это работает нормально, но когда я запускаю свое приложение, это результат.
Как я могу это исправить?? Мне нужна кнопка с шириной == высота.
большое спасибо
2 ответа
Я группирую все кнопки в макете таблицы, это код
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/b_0xa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_0xa" />
<Button
android:id="@+id/b_0xb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_0xb" />
<Button
android:id="@+id/b_0xc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_0xc" />
<Button
android:id="@+id/b_0xd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_0xd" />
<Button
android:id="@+id/b_0xe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_0xe" />
<Button
android:id="@+id/b_0xf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_4xb" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/b_1xa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_1xa" />
<Button
android:id="@+id/b_1xb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_1xb" />
<Button
android:id="@+id/b_1xc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_1xc" />
<Button
android:id="@+id/b_1xd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_1xd" />
<Button
android:id="@+id/b_1xe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_1xe" />
<Button
android:id="@+id/b_1xf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:text="@string/b_4xb" />
</TableRow>
Есть несколько способов, я не уверен, но хочу позволить вам попробовать вещи ниже.
1) Удалить android:layout_weight="1"
,
2) установить статическую высоту и вес в xml как layout_width = "50dip" layout_Height = "50dip"
3) установите Height в Activity/onCreate, проверив параметр width. like view.getHeight(); ...