SibinF
SibinF

Reputation: 385

How to load a particular Layout in the xml file in Android

I don't know my question is correct or not. its only my thinking.if it is possible please give your comments.. My question is i have one xml file . it contain several layouts...

is it possible to load only some layout part in the given xml file?? my exact requirement is , see my xml code, it contains 3 types of layouts. in the java part , when i click a button , then only some layout to be display and other are hidden , is this possible or not???

see my xml code

                 <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:background="@drawable/background" >

<TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="122dp"
    android:layout_y="208dp" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </TableRow>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </TableRow>

    <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </TableRow>
</TableLayout>

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="91dp"
    android:layout_y="90dp" >
</RelativeLayout>

</AbsoluteLayout>

Upvotes: 2

Views: 482

Answers (2)

satish kumar rajput
satish kumar rajput

Reputation: 261

You can use ViewFlipper for showing part of entire layout. ViewFlipper can have multiple child layouts to display at different situation like...

<ViewFlipper android:id="@+id/ViewFlipper01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dip">

    <TextView android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="First view is now displayed"></TextView>

    <TextView android:id="@+id/TextView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Second view is now displayed"></TextView>

    <TextView android:id="@+id/TextView03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Third view is now displayed"></TextView>
</ViewFlipper> 

find flipper as..

ViewFlipper flipper = (ViewFlipper)findViewById(R.id.flipper);

ViewFlipper shows one child(first one) at a time and other remains hidden. now to show other child you can write like...

flipper.setDisplayedChild(index);

Here index refers child number starting from 0, 1, 2,....

Hope it will help you.

Upvotes: 1

Sanket Pandya
Sanket Pandya

Reputation: 1095

Set visibility gone in xml code like this and check it

<android:visibility="gone"> to remove the layout 

and set

 <android:visibility="invisible">   to make the layout invisible

Upvotes: 2

Related Questions