私はのres /値/のstyles.xml 2つのチェックボックスのサイズで一度だけ指定したいと彼らの4つの形状がスタイルファイルのドロワブルのサイズはどのように定義できますか?
- のres /描画可能/ cb1_checked.xml
- RESを/ドローアブル描画可能/ cb1_unchecked.xml
- のres /描画可能/ cb2_checked.xml
- のres /描画可能/ cb2_unchecked.xml。
この方法では、サイズはドロワブルではなく、スタイルで1回表示されます。
以下の2つの試みはどちらも機能しません。あなたは解決策を提案できますか? (これらの2つの試みで何が間違っているか分かりましたら、それを言及してください)
----------------------------- ----------------------------------- 試行1 ----------- -------------------------------------------------- ---
で
RES /描画可能/ cb1_checked.xml
<size android:width="24dp"
android:height="24dp" />
を交換
RES /値/のstyles.xml
<item name="android:layout_width">24dp</item>
<item name="android:layout_height">24dp</item>
------------------------------- --------------------------------- 試行2 ------------- -------------------------------------------------- -
追加
のres /値/のstyles.xml
<item name="android:background">cb_background</item>
と描画可能
RES /描画可能/ cb_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00FF00"/>
<size android:width="24dp"
android:height="24dp" />
</shape>
背景を定義-------------------- -------------------------------------------- --- -------------------------------------------------- -----------
XMLファイルの完全なセットは次のとおりです。
RES /レイアウト/ activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MyLL"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/cb1"
style="@style/CB_style"
android:button="@drawable/cb1_selector"
android:height="@dimen/my24sp" />
<CheckBox
android:id="@+id/cb2"
style="@style/CB_style"
android:button="@drawable/cb2_selector"
android:height="@dimen/my24sp" />
</LinearLayout>
RES /値/スタイル。XML
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
<style name="CB_style" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:gravity">center</item>
<item name="android:checked">false</item>
</style>
RES /描画可能/ cb1_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize="true">
<item android:state_checked="true"
android:drawable="@drawable/cb1_checked" />
<item android:state_checked="false"
android:drawable="@drawable/cb1_unchecked" />
</selector>
RES /描画可能/ cb1_checked.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF0000"/>
<size android:width="24dp"
android:height="24dp" />
</shape>
のres /描画可能/ cb1_unchecked.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#880000"/>
<size android:width="24dp"
android:height="24dp" />
</shape>
(CB2セレクタのと同様に及び/未チェックドローアブルをチェックする)
私は文字通り同じことをやっており、この答えが機能します。 OPはこの答えを受け入れるべきです。 –
私は同じことをしましたが、それは仕事ではありません。次のエラーがあります。エラー:エラー:幅(0)と高さ(0)は<= 0 'にはできません。私はmin skd tarketを19に設定しています。 – roroinpho21
@ roroinpho21これは簡単なことですが、ここで示唆できるものは単なる推測です。ダブルチェックして質問を投稿してください。 – Calaf