RadioButton+Fragment 实现导航栏碰到的一些常见问题

解决一个activity中,多个已被初始化的fragment UI 重叠问题

两个fragment重叠的效果:


解决方式: 为了解决多个已被初始化的fragment UI 重叠问题

在activity的oncreate()方法中:

    getSupportFragmentManager().beginTransaction()
            .show(receiptFragment)
            .hide(notReceiptFragment)
            .commit();
复制代码

ps:一定要commit

一个activity嵌套2个fragment,如上ReceiptFragment/NotReceiptFragment都需要展示API数据,那么请求服务器的代码应该写在activity中还是fragment中,解决方式:

  • 在activity中onCreate()进行网络请求,
  • 通过activity传值给fragment,或者保存数据库的方式,在fragment中获取数据,
  • onActivityCreated方法中进行UI渲染

RadioGroup使用的一些细节

http://blog.sina.com.cn/s/blog_61e26bcb0100vgko.html

<!--两种方法的区别
    @drawable/shouye_p:需要将资源文件放在drawable文件夹中
    @mipmap/shouye_p:需要将资源文件放在xhdpi文件夹中

    如图片本身已经带了文字,不想设置文字,只想设置图片,可以设置其background属性,控制其边距就可以
    http://blog.sina.com.cn/s/blog_61e26bcb0100vgko.html
    自定义标题栏
    http://blog.csdn.net/g777520/article/details/51395445

    <item android:state_checked="true" android:drawable="@drawable/shouye_p"></item>
    <item android:state_checked="false" android:drawable="@drawable/shouye_u"></item>
    <item android:state_checked="true" android:drawable="@mipmap/shouye_p"></item>
    <item android:state_checked="false" android:drawable="@mipmap/shouye_u"></item>-->


<RadioGroup
    android:id="@+id/radioGroup"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="#E8E8E8"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingBottom="4dp"
    android:paddingTop="4dp"
    android:minHeight="50dp"

    >

    <RadioButton
        android:id="@+id/btn_home"
        android:drawableTop="@drawable/check_report_selector"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:button="@null"
        android:text="检查报告"
        android:textSize="14sp"
        android:gravity="center"
        android:textColor="@color/radiobutton_textcolor"
        />

    <RadioButton
        android:id="@+id/btn_classify"
        android:drawableTop="@drawable/unknow_selector"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:button="@null"
        android:text="血糖血压"
        android:textSize="14sp"
        android:gravity="center"
        android:textColor="@color/radiobutton_textcolor"
        />

    <RadioButton
        android:id="@+id/btn_discover"
        android:drawableTop="@drawable/daily_report_selector"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:button="@null"
        android:textSize="14sp"
        android:gravity="center"
        android:text="日常记录"
        android:textColor="@color/radiobutton_textcolor"
        />
</RadioGroup>
复制代码

转载于:https://juejin.im/post/5a3334336fb9a0451a766c88

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值