android 中radiogroup滑动切换,巧妙实现缺角radiogroup控制多个fragment切换和滑动
在android開發中,用一個radiogroup控制多個fragment切換是十分常見的需求。但是如果fragment是一個ListView,如何保證滑動的時候通過缺角可以看到下面的listview是一個難點。
直接上圖:
(1)完美效果
(2)較差效果
另外,不妨假設缺角的高度是5dp,整個radioGroup的高度是50dp.還要求,不能遮擋listVIew第一個元素。
下面是我的主布局xml代碼:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff5f5f5"
android:orientation="vertical" >
android:id="@+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_marginTop="45dp"
android:background="#f5f5f5"
/>
android:id="@+id/head_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
android:id="@+idtton_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:id="@+id/new_tag_button"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/tab_radio_selector"
android:button="@color/trans_parent"
android:checked="true"
android:gravity="center"
android:text="最新"
android:textColor="#858585"
android:textSize="@dimen/font_size_38px" >
android:layout_width="1px"
android:layout_height="fill_parent"
android:background="#d2d2d2" />
android:id="@+id/hot_tag_button"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/tab_radio_selector"
android:button="@color/trans_parent"
android:gravity="center"
android:text="最熱"
android:textColor="#858585"
android:textSize="@dimen/font_size_38px" >
另外,還需要對每個fragment的listView做如下處理
listView.addHeaderView(view);
這個view的背景設置為和listView中item的rootView背景一致,寬為fill_parent,高為5dp即可。要知道,只有headview是可以跟隨item一起滑動的哦,這個才是這個方案實現的關鍵!
總結
以上是生活随笔為你收集整理的android 中radiogroup滑动切换,巧妙实现缺角radiogroup控制多个fragment切换和滑动的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 男生第一个奔出考场:自信985肯定有了
- 下一篇: 软件测试菲律宾,英雄联盟手游菲律宾测试资