I want to make TabHost like ViewPager can flip

178 views Asked by At

My English is pretty basic, please don't mind....

I have a app use TabHost and TabWidget.

Only one Activity , comprising fire layouts.

When Activity start , data will be transmitted to the Layout instant updates.

I want to make it like ViewPagercan flip.

I used ViewPager, But it can not contain more than one Layout in an Activity.

Layout and can not immediately update the information displayed.

Is there any way you can flip it slide?Or make Viewpgaer improved?

public class MainActivity extends Activity
{
    TabHost mTabHost;
    TextView textview1;
    Button button1;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTabHost = (TabHost) findViewById(R.id.tabhost);
        mTabHost.setup();

        TabSpec tspec1 = mTabHost.newTabSpec("tab_1");
        tspec1.setIndicator("1");
        tspec1.setContent(R.id.layout1);
        mTabHost.addTab(tspec1);

        TabSpec tspec2 = mTabHost.newTabSpec("tab_2");
        tspec2.setIndicator("2");
        tspec2.setContent(R.id.layout2);
        mTabHost.addTab(tspec2);

        TabSpec tspec3 = mTabHost.newTabSpec("tab_3");
        tspec3.setIndicator("3");
        tspec3.setContent(R.id.layout3);
        mTabHost.addTab(tspec3);

        TabSpec tspec4 = mTabHost.newTabSpec("tab_4");
        tspec4.setIndicator("4");
        tspec4.setContent(R.id.layout4);
        mTabHost.addTab(tspec4);

        textview1 = (TextView)findViewById(R.id.textView1);
        textview1.setText("111111111");
        button1 = (Button)findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                textview1.setText("2222222222222");
            }
        });
    }
}

xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#007799"
android:orientation="vertical" >

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#00000000"
        android:orientation="vertical" >

        <HorizontalScrollView
            android:id="@+id/mhorizontalScrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal" >

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </TabWidget>
            </LinearLayout>
        </HorizontalScrollView>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <include layout="@layout/page1" />

            <include layout="@layout/page2" />

            <include layout="@layout/page3" />

            <include layout="@layout/page4" />

        </FrameLayout>
    </LinearLayout>
</TabHost>

</LinearLayout>

Whatever, thanks for your view.

0

There are 0 answers