在布局动态视图 [英] Dynamic Views in Layout
本文介绍了在布局动态视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的XML我在第一个3视图
In my xml i have 3 view at first
我要隐藏一个观点那之后我要取消隐藏程序。
i have to hide one view then after that i have to unhide that in program.
当我隐藏视图中的其他必须调整,当我取消隐藏它有调整
When i hide that view the other must adjust and when i unhide it have to adjust
推荐答案
假设你有一个这样的布局
Suppose you have a layout like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/linearLayout"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<!-- your content here -->
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<!-- your content here -->
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout03"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<!-- your content here -->
</LinearLayout>
</LinearLayout>
在你的程序中使用的起始
At the starting of your program use
LinearLayout linearLayout1,linearLayout2,linearLayout3;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
//define and declare the layouts
linearLayout1=(LinearLayout) findViewById(R.id.LinearLayout01);
linearLayout2=(LinearLayout) findViewById(R.id.LinearLayout02);
linearLayout3=(LinearLayout) findViewById(R.id.LinearLayout03);
}
现在,当你要隐藏的第一个布局,用
Now when you want to hide the first layout ,use
linearLayout1.setVisibility(View.GONE);
现在,当你想要显示的第一个布局,用
Now when you want to show the first layout ,use
linearLayout1.setVisibility(View.VISIBLE);
的情况同样为所有布局。
The situation is same for all layouts..
希望这会帮助你。
这篇关于在布局动态视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文