android編程實(shí)現(xiàn)局部界面動(dòng)態(tài)切換的方法
本文實(shí)例講述了android編程實(shí)現(xiàn)局部界面動(dòng)態(tài)切換的方法。分享給大家供大家參考,具體如下:
局部界面固定,局部界面可以動(dòng)態(tài)切換。效果如下:



這個(gè)效果由3個(gè)layout構(gòu)成
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程序設(shè)計(jì)有所幫助。
- Android使用ViewPager實(shí)現(xiàn)頂部tabbar切換界面
- Android實(shí)現(xiàn)界面左右滑動(dòng)切換功能
- Android輸入法與表情面板切換時(shí)的界面抖動(dòng)問題解決方法
- Android實(shí)現(xiàn)閃屏及注冊和登錄界面之間的切換效果
- PagerSlidingTabStrip制作Android帶標(biāo)簽的多界面滑動(dòng)切換
- Android App仿微信界面切換時(shí)Tab圖標(biāo)變色效果的制作方法
- Android應(yīng)用中使用ViewPager實(shí)現(xiàn)類似QQ的界面切換效果
- Android界面切換出現(xiàn)短暫黑屏的解決方法
- Android實(shí)現(xiàn)Activity界面切換添加動(dòng)畫特效的方法
- Android studio實(shí)現(xiàn)兩個(gè)界面間的切換
相關(guān)文章
Kotlin中Stack與LinkedList的實(shí)現(xiàn)方法示例
這篇文章主要給大家介紹了關(guān)于Kotlin中Stack與LinkedList實(shí)現(xiàn)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-06-06
Android仿淘寶首頁頭條View垂直滾動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Android仿淘寶首頁頭條View垂直滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
Android通過ViewModel保存數(shù)據(jù)實(shí)現(xiàn)多頁面的數(shù)據(jù)共享功能
這篇文章主要介紹了Android通過ViewModel保存數(shù)據(jù)實(shí)現(xiàn)多頁面的數(shù)據(jù)共享功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11
Android spinner下垃菜單用法實(shí)例詳解
這篇文章主要介紹了Android spinner下垃菜單用法,詳細(xì)分析了spinner下垃菜單的定義、布局及功能實(shí)現(xiàn)相關(guān)技巧,需要的朋友可以參考下2016-07-07
Android Native庫的加載及動(dòng)態(tài)鏈接的過程
這篇文章主要介紹了Android Native庫的加載及動(dòng)態(tài)鏈接的加載過程,需要的朋友可以參考下2018-01-01

