Shehzad
Shehzad

Reputation: 2940

How to create a Stack Panel menu in Android SDK?

I'd like to create a menu for my widget configuration similar like GWT Stack Panel

Is it posible to create similar type of Menu in android.? Any Help or suggestions are welcome.

Upvotes: 3

Views: 4906

Answers (1)

AliSh
AliSh

Reputation: 10619

use this layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:text="Bt1"
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"></Button>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:id="@+id/linearLayout1">
        <ImageView
            android:layout_width="wrap_content"
            android:id="@+id/imageView1"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"></ImageView>
    </LinearLayout>
    <Button
        android:text="Bt2"
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"></Button>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:id="@+id/linearLayout2">
        <ImageView
            android:layout_width="wrap_content"
            android:id="@+id/imageView2"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"></ImageView>
    </LinearLayout>
    <Button
        android:text="Bt3"
        android:id="@+id/button3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"></Button>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:id="@+id/linearLayout3">
        <ImageView
            android:layout_width="wrap_content"
            android:id="@+id/imageView3"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"></ImageView>
    </LinearLayout>
</LinearLayout>

and use this code :

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    findViewById(R.id.linearLayout1).setVisibility(View.GONE);
    findViewById(R.id.linearLayout2).setVisibility(View.GONE);
    findViewById(R.id.linearLayout3).setVisibility(View.GONE);

    Button bt1=(Button) findViewById(R.id.button1);
    Button bt2=(Button) findViewById(R.id.button2);
    Button bt3=(Button) findViewById(R.id.button3);
    bt1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            findViewById(R.id.linearLayout1).setVisibility(View.VISIBLE);
            findViewById(R.id.linearLayout2).setVisibility(View.GONE);
            findViewById(R.id.linearLayout3).setVisibility(View.GONE);
        }
    });
    bt2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            findViewById(R.id.linearLayout1).setVisibility(View.GONE);
            findViewById(R.id.linearLayout2).setVisibility(View.VISIBLE);
            findViewById(R.id.linearLayout3).setVisibility(View.GONE);
        }
    });
    bt3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            findViewById(R.id.linearLayout1).setVisibility(View.GONE);
            findViewById(R.id.linearLayout2).setVisibility(View.GONE);
            findViewById(R.id.linearLayout3).setVisibility(View.VISIBLE);
        }
    });
}

you can use your layout in the linearlayout1,linearlayout2 and linearlayout3 for build stack panel for android.

Upvotes: 3

Related Questions