Android+界面+动态,android编程实现局部界面动态切换的方法

本文实例讲述了android编程实现局部界面动态切换的方法。分享给大家供大家参考,具体如下:

局部界面固定,局部界面可以动态切换。效果如下:

16221674509b4503a031210507f0d429.png

955e65badba9567d0552fc0f29799cc3.png

397a54bf44c3e6c3021172a90c9dcbb7.png

这个效果由3个layout构成

main.xml

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal" >

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

android:background="@android:color/black" >

android:id="@+id/btnSwitch"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="switch" />

android:id="@+id/btnScreen"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="screen" />

android:id="@+id/frameSwitch"

android:layout_width="160dp"

android:layout_height="fill_parent"

android:background="@android:color/white" >

one.xml

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@color/yellow"

android:orientation="vertical" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="this is linearLayout one" />

two.xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="this is linearLayout two" />

android:id="@+id/btnSecond"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="btnSecond" />

下面是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程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值