Dynamic Views in Layout
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 m开发者_Go百科ust 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..
Hope this will help you..
精彩评论