开发者

How to make a horizontal-switchable activities

开发者 https://www.devze.com 2023-02-02 06:47 出处:网络
I have an application about debts to user and user\'s debts. Main activity is TabActivity for switching two activities with custom lists.

I have an application about debts to user and user's debts. Main activity is TabActivity for switching two activities with custom lists.


It looks like (screenshot): http://i.stack.imgur.com/qts1f.png

The code is:

public class MainActivity extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        TextView tv = (TextView)findViewById(R.id.newDebtHeader);
        tv.setBackgroundResource(R.drawable.grad);
        tv.setTextColor(Color.BLACK);
        tv.setFadingEdgeLength(3);

        intent = new Intent().setClass(this, DebtsToMeList.class);

        spec = tabHost.newTabSpec("debts_to_me").setIndicator(null, res.getDrawable(R.drawable.ic_tab_debts_to_me)).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, MyDebtsList.class);

        spec = tabHost.newTabSpec("my_debts").setIndicator(null, res.getDrawable(R.drawable.ic_tab_my_debts)).setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(2);
    }
}

main.xml is:

<?xml version="1.0" encoding="utf-8"?>
 <Li开发者_如何转开发nearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="1dp">

    <TextView 
        android:id="@+id/newDebtHeader" 
        android:layout_height="24dip"
        android:layout_width="fill_parent"
        android:gravity="center_vertical|center_horizontal"
        android:textStyle="bold"
        android:textSize="16dip" 
        android:text="хДолги">
    </TextView> 
    <TabHost 
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="5dp" />
        </LinearLayout>
    </TabHost>
</LinearLayout>
enter code here

But I don't like TabActivity, I want change this two lists by horizontal finger drag. Could you please help me change my code?


If you look at this example, it uses the fling gesture with a view switcher and a little animation to get the effect I think that you are looking for... all that you would have to do is load your lists and then you should be able to swipe between them.

Hope this helps.


It sounds to me like you want to utilize a Gallery, where the Gallery adapter creates your custom list views. Unfortunately this isn't as straightforward as it might seem. See Embedding ListView inside Gallery.

0

精彩评论

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

关注公众号