Good day, I am a little confused and sorry if it is dublicated, but I cant find correct answer. My task is to create widget (RadioButton, RatingBar) with custom drawables + make them high quality and not blur.
Here comes my problems and what I have tried. So, for example, I have custom drawable for radio buttons:
radioButtonArray[i].setButtonDrawable(R.drawable.radio_button_selector);
radio_button_selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/rb_unchecked" android:state_checked="false"/>
<item android:drawable="@drawable/rb_checked" android:state_checked="true"/>
</selector>
Now the problem is in quality of drawables. If I will add rb_unchecked.png
and rb_checked.png
in different folders (hdpi,mdpi,xhdpi...) with different px size, then my radio buttons will be enourmous big on some phone screens. Ok, next thing that I tried was to set programmatically width and height of my radio buttons, but found that it is hard and unefficient (for example, I have the same situation with RatingBar and I cant find how to set custom width and height of items in it). Another solution that I tried is to add rb_unchecked.png
and rb_checked.png
only to drawable
folder with size of 18px*18px and, on the one hand it solved the problem, size is correct, but the radio buttons now are low resolution and kind of blur.
My quastion is what I am doing wrong? I expected that on devices with different dp android will take specific image in hdpi/xhdpi folder and scale it to specific size, but instead of this images from specific folders just wrap_content | crop in my custom widget?
答案 0 :(得分:0)
我找到了为什么我的radiobutton drawable很大,我使用了以下布局:
<RadioButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="30dp"
android:layout_height="30dp"
android:button="@drawable/radio_button_selector"/>
正确的方法:
<RadioButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/radio_button_selector"
android:button="@android:color/transparent"/>