使用Listview在Tab布局中显示帖子

时间:2015-12-08 20:36:10

标签: android listview android-listview

我在我的Android应用程序的Tab Layout上使用Listview从网络加载数据。 Tha标签工作正常,我可以轻松地在我的标签之间切换,没有任何错误,但当列表视图填充来自服务器的数据时,标签消失,我有一个简单的数据列表视图。我再也看不到其他标签了。 PS数据加载正常没有任何问题。

这是home_layout的主页java代码

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_layout);

    TabHost tabHost = getTabHost();

    TabHost.TabSpec myprofiletab = tabHost.newTabSpec("Profile");
    myprofiletab.setIndicator("Profile",getResources().getDrawable(R.drawable.myprofile_icon));
    Intent myprofileintent = new Intent(this,MyProfile.class);
    myprofiletab.setContent(myprofileintent);

    TabHost.TabSpec newsfeedtab = tabHost.newTabSpec("NewsFeed");
    newsfeedtab.setIndicator("Feed",getResources().getDrawable(R.drawable.newsfeed_icon));
    Intent feed = new Intent(this,NewsFeed.class);
    newsfeedtab.setContent(feed);

    tabHost.addTab(newsfeedtab);
    tabHost.addTab(myprofiletab);
}

这是home_layout

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_height="fill_parent">
<RelativeLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

通过向FrameLayout添加一行

解决了我的问题
        <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@android:id/tabs" />
相关问题