編輯:Android開發教程
前言
一般頻繁切換Fragment會導致頻繁的釋放和創建,如果Fragment比較臃腫體驗就非常不好了,這裡分享一個方法。
一、應用場景
1、不使用ViewPager
2、不能用replace來切換Fragment,會導致Fragment釋放(調用onDestroyView)
二、實現
1、xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1.0" >
</FrameLayout>
<RadioGroup
android:id="@+id/main_radio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="bottom"
android:layout_marginBottom="-6dp"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radio_button0"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/bottom_1" />
<RadioButton
android:id="@+id/radio_button1"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/bottom_2" />
<RadioButton
android:id="@+id/radio_button2"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/bottom_3" />
<RadioButton
android:id="@+id/radio_button3"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/bottom_4" />
<RadioButton
android:id="@+id/radio_button4"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/bottom_5" />
</RadioGroup>
</LinearLayout>
代碼說明:
非常常見的底部放5個RadioButton,點擊切換不同的Fragment。
android技巧:android xml布局總結
一.背景可能很多人跟我一樣,做了好久的android程序,卻一直沒有認真地坐下來好好學習下xml文件的布局。其實有的時候我們用view繪制或是利用ADT的圖形界面功能就可
Android開發入門(十四)顯示圖像 14.1 Gallery和ImageView
Gallery可以顯示一系列的圖片,並且可以橫向滑動。下面展示如何使用Gallery去顯示一系列的圖片。1. 創建一個工程,Gallery。2. main.xml中的代碼
Android滑動效果進階篇(六) 倒影效果
上篇介紹了使用Animation實現3D動畫旋轉翻頁效果,現在介紹圖片倒影實現,先看效果圖本示例主要通過自定義Gallery和ImageAdapter(繼承自BaseAd
Android多線程研究(1) 線程基礎及源碼剖析
從今天起我們來看一下Android中的多線程的知識,Android入門容易,但是要完成一個完善的產品卻不容易,讓我們從線程開始一步步深入Android內部。一、線程基礎回