• Android中如何设置RadioButton在文字的右边,图标在左边


    from:http://blog.csdn.net/sunnyfans/article/details/7901592?utm_source=tuicool&utm_medium=referral

    Android中如何设置RadioButton在文字的右边,图标在左边???

    解决方法  :
    第一步:
    android:button="@null"这条语句将原来系统的RadioButton图标给隐藏起来。
    第二步:
     android:drawableRight="@android:drawable/btn_radio"这条语句
    在原来图标的右边添加一个系统自带的btn_radio图标,我想RadioButton就是在btn_radio图标上进行封装而已。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <RadioGroup
            android:id="@+id/radioGroup1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <RadioButton
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
               android:button="@null"
                android:checked="true"
                android:drawableRight="@android:drawable/btn_radio"
                android:paddingLeft="10dp"
                android:text="RadioButton" />

            <RadioButton
                android:id="@+id/button2"
                android:layout_width="319dp"
                android:layout_height="wrap_content"
                android:button="@null"
                android:drawableRight="@android:drawable/btn_radio"
                android:paddingLeft="10dp"
                android:text="RadioButton" />

        </RadioGroup>
    </LinearLayout>

    demo下载
    http://download.csdn.net/detail/sunnyfans/4521592

    附参考网站:
    http://www.haogongju.net/art/1422253


    小结:

    今天在实现RadioGroup单选时,要求文字在左边,选择图标在右边,而android系统自带的RadioGroup是图标在左边,文字在右边,既然我有这个需求,遇到这个问题,那么肯定有其他人也有这个需求,于是也就应该有实现它的方法。因为问题已经发生了,这个世界也就是在不断解决未知问题的过程中不断发展进步,即:需求,问题是发明、发展的原始推动力。知识是为解决问题,或者描述某现象的而诞生。所以以后不管遇到什么问题,不要畏惧,既然问题已经发生了,即一定会有解决它的办法,这时就需要自己去思考,思考这个问题发生的环境,分析问题,然后定位问题原因(二分法)<先猜测,再求证>,定位后再思考如何去解决。不断提醒自己养成这种遇到问题,分析问题,进而尝试去解决问题的习惯。

    知识收获:
    认识到android系统图标的重要性,可以这样使用:
     android:button="@null"将图标给隐藏,然后再用android:drawableRight="@android:drawable/btn_radio"在右边再生成一个图标,再用android:text="文字内容"在隐藏图标的位置显示文字。
    反复思考:
     android:button="@null"
    android:drawableRight="@android:drawable/btn_radio
    这提供了一种通用方法。

    附:demo下载
    http://download.csdn.net/detail/sunnyfans/4521592
  • 相关阅读:
    FastAdmin 提示框 toastr 改变文字
    FastAdmin 将会员模块升级为基础模块的升级指导
    随笔
    随笔
    c++11 lambda(了解)
    c++11 类型推断
    boost::archive::text_oarchive
    std::ostringstream
    随笔
    随笔1
  • 原文地址:https://www.cnblogs.com/94cool/p/5411953.html
Copyright © 2020-2023  润新知