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

2019-12-10 19:55:06王冬梅
  • 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代码

     

     
    1. public class ZzzAndroidActivity extends Activity {  private LinearLayout frameSwitch; 
    2. /** Called when the activity is first created. */  @Override 
    3. public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState); 
    4. setContentView(R.layout.main);  frameSwitch = (LinearLayout) findViewById(R.id.frameSwitch); 
    5. Button btnSwitch = (Button) findViewById(R.id.btnSwitch);  btnSwitch.setOnClickListener(new OnClickListener() { 
    6. boolean boo = false;  @Override 
    7. public void onClick(View v) {  boo = !boo; 
    8. if (boo) {  getViewOne(); 
    9. } else {  getViewSecond(); 
    10. }  } 
    11. });  /* 
    12. * 是否全屏  */ 
    13. Button btnScreen = (Button) findViewById(R.id.btnScreen);  btnScreen.setOnClickListener(new OnClickListener() {