android編程實現(xiàn)局部界面動態(tài)切換的方法
更新時間:2015年11月11日 15:41:00 作者:jie1991liu
這篇文章主要介紹了android編程實現(xiàn)局部界面動態(tài)切換的方法,以實例形式較為詳細的分析了Android局部切換的布局及功能實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了android編程實現(xiàn)局部界面動態(tài)切換的方法。分享給大家供大家參考,具體如下:
局部界面固定,局部界面可以動態(tài)切換。效果如下:
這個效果由3個layout構成
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="@android:color/black" > <Button android:id="@+id/btnSwitch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="switch" /> <Button android:id="@+id/btnScreen" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="screen" /> </LinearLayout> <LinearLayout android:id="@+id/frameSwitch" android:layout_width="160dp" android:layout_height="fill_parent" android:background="@android:color/white" > </LinearLayout> </LinearLayout>
one.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/yellow" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="this is linearLayout one" /> </LinearLayout>
two.xml
<?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" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="this is linearLayout two" /> <Button android:id="@+id/btnSecond" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btnSecond" /> </LinearLayout>
下面是Java代碼
public class ZzzAndroidActivity extends Activity { private LinearLayout frameSwitch; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); frameSwitch = (LinearLayout) findViewById(R.id.frameSwitch); Button btnSwitch = (Button) findViewById(R.id.btnSwitch); btnSwitch.setOnClickListener(new OnClickListener() { boolean boo = false; @Override public void onClick(View v) { boo = !boo; if (boo) { getViewOne(); } else { getViewSecond(); } } }); /* * 是否全屏 */ Button btnScreen = (Button) findViewById(R.id.btnScreen); btnScreen.setOnClickListener(new OnClickListener() { boolean isScreen = false; @Override public void onClick(View v) { isScreen = !isScreen; if (isScreen) { frameSwitch.setVisibility(android.view.View.GONE); } else { frameSwitch.setVisibility(android.view.View.VISIBLE); } } }); } public void getViewOne() { View viewOne = getLayoutInflater().inflate(R.layout.one, null); frameSwitch.removeAllViews(); frameSwitch.addView(viewOne, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); } public void getViewSecond() { View viewSecond = getLayoutInflater().inflate(R.layout.two, null); Button btn = (Button) viewSecond.findViewById(R.id.btnSecond); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(ZzzAndroidActivity.this, "hello world", Toast.LENGTH_LONG).show(); } }); frameSwitch.removeAllViews(); frameSwitch.addView(viewSecond, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); } }
希望本文所述對大家Android程序設計有所幫助。
您可能感興趣的文章:
- Android使用ViewPager實現(xiàn)頂部tabbar切換界面
- Android實現(xiàn)界面左右滑動切換功能
- Android輸入法與表情面板切換時的界面抖動問題解決方法
- Android實現(xiàn)閃屏及注冊和登錄界面之間的切換效果
- PagerSlidingTabStrip制作Android帶標簽的多界面滑動切換
- Android App仿微信界面切換時Tab圖標變色效果的制作方法
- Android應用中使用ViewPager實現(xiàn)類似QQ的界面切換效果
- Android界面切換出現(xiàn)短暫黑屏的解決方法
- Android實現(xiàn)Activity界面切換添加動畫特效的方法
- Android studio實現(xiàn)兩個界面間的切換
相關文章
Kotlin中Stack與LinkedList的實現(xiàn)方法示例
這篇文章主要給大家介紹了關于Kotlin中Stack與LinkedList實現(xiàn)的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考借鑒,下面隨著小編來一起學習學習吧2018-06-06Android通過ViewModel保存數(shù)據(jù)實現(xiàn)多頁面的數(shù)據(jù)共享功能
這篇文章主要介紹了Android通過ViewModel保存數(shù)據(jù)實現(xiàn)多頁面的數(shù)據(jù)共享功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-11-11Android Native庫的加載及動態(tài)鏈接的過程
這篇文章主要介紹了Android Native庫的加載及動態(tài)鏈接的加載過程,需要的朋友可以參考下2018-01-01