如何在 Android 的 Radiobuttons 中缩放圆圈 [英] How to scale the circle in Radiobuttons in Android

查看:68
本文介绍了如何在 Android 的 Radiobuttons 中缩放圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android 中使用了一些定制的 RadioButtons,我希望它们能随屏幕尺寸缩放.这就是为什么我使用可缩放大小单位来处理这个库中的文本和 UI 元素

代码如下:约束布局中的单选按钮:

 

后台文件

<选择器 xmlns:android="http://schemas.android.com/apk/res/android"><项目机器人:state_checked =真";android:drawable="@drawable/state_checked";/><item android:drawable="@drawable/state_unchecked"/></选择器>

状态文件已检查"

<shape android:shape=矩形"xmlns:android=http://schemas.android.com/apk/res/android"><solid android:color="@color/colorBlue></固体><corners android:radius="@dimen/_25sdp></corners></形状>

和状态未选中"

<shape android:shape=矩形"xmlns:android=http://schemas.android.com/apk/res/android"><solid android:color="@color/colorTest"></固体><corners android:radius="@dimen/_25sdp></corners></形状>

你知道我如何也可以缩放 RadioButtons 的圆圈吗?

谁能想到一个简单的解决方案来做到这一点?我的意思是我无法想象,对于平板电脑,您不能真正使用 RadioButtons,我不明白为什么可以调整按钮的大小,而无法调整内圈的大小并且无法缩放.

解决方案

单选按钮是一个内置控件组件,因此它的大小是固定的.但是如果你需要让它更小,你可以使用:

这是一种解决方法,不应该用来使它变大,因为按钮会像素化

I am using some customized RadioButtons in Android and I want them so scale with the screen size. This is why I am using scalable size units for text and UI elements from this libraries https://github.com/intuit/sdp and https://github.com/intuit/ssp

Unfortunately, while the text itself and the bottom size scales with a higher screen size, the circle remains of equal size which does not look good. You can see it on my screenshots:

Here you see the code: Radio Button in the constraintLayout:

  <RadioButton
        android:id="@+id/r_Button_Small"
        android:layout_width="@dimen/_73sdp"
        android:layout_height="@dimen/_28sdp"
        android:layout_weight="1"
        android:textSize="@dimen/_12ssp"
        android:background="@drawable/background_selector"
        android:text="@string/small"
        android:textColor="@drawable/text_selector"
        android:gravity="center"
        android:textAlignment="center"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.322"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="@dimen/_50sdp"
        app:layout_constraintVertical_bias="0.584"
         />

Background files

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_checked="true"
        android:drawable="@drawable/state_checked" />

    <item android:drawable="@drawable/state_unchecked" />

</selector>

with state file "checked"

<?xml version="1.0" encoding="UTF-8"?>
<shape android:shape="rectangle"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/colorBlue">
    </solid>
    <corners android:radius="@dimen/_25sdp"></corners>
</shape>

and "state unchecked"

<?xml version="1.0" encoding="UTF-8"?>
<shape android:shape="rectangle"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/colorTest">
    </solid>
    <corners android:radius="@dimen/_25sdp"></corners>
</shape>

Do you know how I can also scale the circle of the RadioButtons?

Can anyone think about an easy solution for doing that? I mean I can't imagine that for tablets you can't really use RadioButtons and I do not understand why the size of the button can be adjusted while the inner circle can't be adjusted with regard to the size and does not scale.

解决方案

the radio button is a built-in control component and as such its size is fixed. But if you need to make it smaller you could use:

<RadioButton
  android:scaleX="0.7"
  android:scaleY="0.7" />

It's a workaround and shouldn't be used to make it bigger because button will get pixelated

这篇关于如何在 Android 的 Radiobuttons 中缩放圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆