按钮需要填写父单选按钮 [英] button needs to fill parent radiobutton

查看:48
本文介绍了按钮需要填写父单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个单选按钮的单选组.每个按钮都有一个自定义选择器.我希望选择器中的drawable能够填写单选按钮的宽度.在不同的分辨率下,按钮看起来会有所不同.我没有使用九个补丁,所以这很有意义,但是即使我是我也不知道如何使按钮可绘制拉伸.以下是无线电组和选择器的代码.宽度不同于摆弄.

I have a radio group with two radiobuttons. each button has a custom selector. I would like for the drawable in the selector to fill out the width of the radio button. Under different resolutions the button looks different. I am not using a nine-patch so this makes sense but even if i was I am not sure how to make the button drawable stretch. Below is the code for the radio group and a selector. widths are different from fiddling around.

布局xml:

            <RadioButton
                android:id="@+id/radiomale"
                android:layout_width="126dp"
                android:layout_height="50dp"
                android:minHeight="50dp"
                android:minWidth="126dp"
                android:button="@layout/signupmale"

                />

            <RadioButton
                android:id="@+id/radiofemale"
                 android:layout_width="128dp"
                android:layout_height="50dp"
                android:minHeight="50dp"
                android:minWidth="128dp"
                android:button="@layout/signupfemale" />
        </RadioGroup>

选择器:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
    android:drawable="@drawable/genre_male_pressed" />
<item android:state_checked="false" android:state_window_focused="false"
    android:drawable="@drawable/genre_male" />
<item android:state_checked="true" android:state_pressed="true"
    android:drawable="@drawable/genre_male_pressed" />
<item android:state_checked="false" android:state_pressed="true"
    android:drawable="@drawable/genre_male" />
<item android:state_checked="true" android:state_focused="true"
    android:drawable="@drawable/genre_male_pressed" />
<item android:state_checked="false" android:state_focused="true"
    android:drawable="@drawable/genre_male" />
<item android:state_checked="false" android:drawable="@drawable/genre_male" android:scaleType="fitXY" />
<item android:state_checked="true" android:drawable="@drawable/genre_male_pressed" android:scaleType="fitXY"/>
</selector>

问题是在不同分辨率下进行测试时,按钮之间会形成间隙.谢谢你的帮助.

The problem is when testing under different resolutions gaps form between the buttons. Thanks for any help.

推荐答案

RadioGroup实际上是 LinearLayout ,因此您可以使用子级的layout_weight控制间距.这可能会有所帮助: Android中的线性布局和权重以及 Android layout_weight comportment

RadioGroup is actually a subclass of LinearLayout so what you could do is use layout_weight of the children to control the spacing. This might be a little helpful: Linear Layout and weight in Android and this Android layout_weight comportment

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="45dip"
        android:weightSum="1"
        android:orientation="horizontal"
        >

        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="40dip"
            android:layout_weight=".5"
            />

        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="40dip"
            android:layout_weight=".5"
            />

    </RadioGroup>

如果单选按钮上有文字,您将需要使用ninepatch,并且可能需要在左侧或右侧使用填充.

You are going to need to use ninepatch and maybe use padding left or right if there is text on the radio buttons.

这篇关于按钮需要填写父单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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