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

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

两个fragment重叠的效果:


微信图片_20171114115613.jpg

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

在activity的oncreate()方法中:

    getSupportFragmentManager().beginTransaction()
            .show(receiptFragment)
            .hide(notReceiptFragment)
            .commit();

ps:一定要commit

微信图片_20171114115618.jpg

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

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

RadioGroup使用的一些细节

图片.png

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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容