0

我有一个关于用户债务和用户债务的应用程序。主要活动是 TabActivity,用于使用自定义列表切换两个活动。


它看起来像(截图):http: //i.stack.imgur.com/qts1f.png

代码是:

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 是:

<?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: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

但我不喜欢 TabActivity,我想通过水平手指拖动来更改这两个列表。你能帮我改一下代码吗?

4

2 回答 2

0

在我看来,您想使用 Gallery,Gallery 适配器会在其中创建您的自定义列表视图。不幸的是,这并不像看起来那么简单。请参阅在 Gallery 中嵌入 ListView

于 2011-01-02T19:32:16.680 回答
0

如果您查看此示例,它使用带有视图切换器和小动画的投掷手势来获得我认为您正在寻找的效果......您所要做的就是加载您的列表,然后您应该是能够在它们之间滑动。

希望这可以帮助。

于 2011-01-02T19:45:18.773 回答