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)兩個界面間的切換
相關文章
解決Android WebView攔截url,視頻播放加載失敗的問題
這篇文章主要介紹了解決Android WebView攔截url,視頻播放加載失敗的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Android實現(xiàn)H5與Native交互的兩種方式
Android實現(xiàn)H5頁面和Native頁面交互的方法有兩種,一種是Url攔截的方法,另一種是JavaScript注入,下面來通過這篇文章分別講解。有需要的朋友們可以參考借鑒,下面來一起看看吧。2016-12-12
Android 配置gradle實現(xiàn)VersionCode自增實例
今天小編就為大家分享一篇Android 配置gradle實現(xiàn)VersionCode自增實例,具有很好的 參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Android實現(xiàn)圖片循環(huán)播放的實例方法
2013-05-05
RecyclerView中監(jiān)聽EditText變化的BUG的解決方法
本篇文章主要介紹了RecyclerView中監(jiān)聽EditText變化的BUG的解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11

