开发者

UI design suggestions for Display and Switching between Multiple Layouts

I'm trying to create an app that offers the user 3 different kinds of layouts. The only common portion for all 3 would be the TextView (located at the top) that would display information specific to the currently displayed layout and 3 buttons to select the required layouts.

Is there some way we can create this UI in XML to keep only one constant part(the upper TextView) and dynamically display any one of the 3 layouts below it? Would it be better to create separate XML's for each of the layouts (each including the upper TextView in them)? OR would doing this via code be better?

Fast switching between the 3 layouts is important.

Appreciate any insights on this.

TIA

[EDIT 1] Actually they are 3 different layouts, with several "child" layouts and views within each of them. Could a ViewFli开发者_C百科pper be used for switching between these? I was thinking that a ViewFlipper was only for switching between View elements?

I do have them in individual XML's right now but am looking for some way to load and unload them fast. Not sure how to do the hiding thing, will try reading up on that. [/EDIT 1]


I would recommend using a Viewflipper for your purpose.

The common portion for the layouts should be kept outside the Viewflipper. A Viewflipper can be declared in XML as

    <ViewFlipper android:id="@+id/splash_more_flipper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:outAnimation="@anim/push_left_out"
        android:inAnimation="@anim/push_left_in">

You can give your own versions of in and out animations given that it exists in /res/anim.

Flipping between views in your Viewflipper is very easy. Here view is flipped upon a button click.

mFlipper = ((ViewFlipper) this.findViewById(R.id.splash_more_flipper));

    Button next = (Button) findViewById(R.id.next);
        next.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mFlipper.showNext();
                mContainer.startAnimation(anim);
            }
        });
    }

You could also add a button to show the previous view and calling

mFlipper.showPrevious();

upon button click.

Hope this helps.


I would create

  • one main layout
  • several individual XML layouts for the 3 layout
  • I would use the include directive in the main layout to load in the 3 XML layouts
  • either hide them individually, or have a ViewFlipper to fast change them
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜