本文介绍了与Android的ViewFlipper更改视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用ViewFlipper改变TabActivity意见,但有点help.I'm真的不知道该怎么办it.Here是我的code:

I need a little help.I'm using a ViewFlipper to change views in TabActivity but not really sure how to do it.Here is my code :

MainActivity.class

MainActivity.class

public class Collections extends Activity implements OnClickListener {

    ViewFlipper vFlip;
    Button genre, recommended, soon;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.collections_layout);

        vFlip = (ViewFlipper) findViewById(R.id.tags_flipper);

        genre = (Button) findViewById(R.id.genre_btn);
        genre.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    vFlip.getCurrentView();
                }

            });
        recommended = (Button) findViewById(R.id.recom_btn);
        recommended.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    vFlip.getCurrentView();
                }

            });
        soon = (Button) findViewById(R.id.soon_btn);
        soon.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    vFlip.getCurrentView();
                }

            });
    }
}

我有三个不同的XML,我想点击buttons.Here加载是collection_layout.xml

I have three different xml, which I want to load with clicking the buttons.Here is the collection_layout.xml

Col​​lection_layout.xml

Collection_layout.xml

<?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"
  android:background="#FFFFFF">

            <LinearLayout
            android:id="@+id/actionbar"
            android:layout_width="fill_parent"
            android:layout_height="65px"
            android:background="@drawable/pink_bar"
            android:tileMode="repeat"
            android:orientation="vertical">

                <ImageView
                    android:src="@drawable/stampii_logo"
                    android:id="@+id/stampii_logo_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:paddingTop="20px"/>

            </LinearLayout>

                <LinearLayout
                android:id="@+id/first_container"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">



                    <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:weightSum="1"
                    android:background="#d229ce">


                    <Button
                        android:id="@+id/genre_btn"
                        android:text="By Genre"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="10dp" />

                    <Button
                        android:id="@+id/recom_btn"
                        android:text="Recommended"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="10dp" />

                    <Button
                        android:id="@+id/soon_btn"
                        android:text="Expect Soon!"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="10dp" />

                    </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:id="@+id/flip"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#FFFFFF" >

                <ViewFlipper
                    android:id="@+id/tags_flipper"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                    <include android:id="@+id/genre" layout="@layout/by_genre" />
                    <include android:id="@+id/recom" layout="@layout/recommended" />
                    <include android:id="@+id/soon" layout="@layout/expect_soon" />
                </ViewFlipper>


        </LinearLayout>


</LinearLayout>

所以,我该怎么办呢?非常感谢!

So how can i do that?Thanks a lot!

推荐答案

使用 ViewFlipper.setDisplayedChild

这篇关于与Android的ViewFlipper更改视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 21:29