我正在开发一个Android应用程序,并使用它来自定义RadioButtons:
<!-- Radio button style -->
<style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton">
<item name="android:button">@drawable/checkbox_unchecked</item>
</style>
但是图像@drawable/checkbox_unchecked
很大。
您知道我如何缩小尺寸吗?
我知道您可以通过减小图像大小来实现所需的功能。但是我建议使用以下代码。这将帮助您设置未选择模式和选择模式的图像。
只需几个步骤,便可以实现此目的:-Image Drawables
为它们的两个状态(选中/未选中)创建。-为这两个可绘制对象创建选择器。样本内容应该是这样的:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/unchecked" />
<item android:state_checked="false" android:drawable="@drawable/checked" />
</selector>
-将此选择器作为android:button
属性添加到RadioButton
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background">
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/checkbox_selector"
android:text="Custom RadioButton" />
</LinearLayout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句