Tabwidget与我的活动内容重叠

Ada*_*son 5 android overlap tabwidget

在花了两天时间寻找答案后,我想就以下行为寻求帮助.

我正在尝试在Android上编写一个简单的tabhost应用程序,每个活动都有一个布局.我设计了我的布局,以便tabwidget出现在屏幕的底部.

在第一个选项卡上,我正在尝试插入一个简单的2行ListView.我的问题是ListView位于底部,但其中一半隐藏在tabwidget后面.我想了解如何使我的ListView显示在tabwidget上方.

这是我的main.xml:

    <?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_height="fill_parent">
    <RelativeLayout
        android:layout_height="fill_parent"
        android:layout_width="fill_parent">

       <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />

       <TabWidget
            android:id="@android:id/tabs"
            android:layout_alignParentBottom="true"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </RelativeLayout>

</TabHost>
Run Code Online (Sandbox Code Playgroud)

这是我的主要app类:

public class TestTabWidget 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

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

        spec = tabHost.newTabSpec("artists").setIndicator("Tab A",
                          res.getDrawable(R.drawable.ic_tab_a))
                      .setContent(intent);
        tabHost.addTab(spec);


        tabHost.setCurrentTab(0);
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的活动代码:

public class AActivity extends Activity {

ListView lvListe;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a_layout);
        lvListe = (ListView)findViewById(R.id.lvListe);
        lvListe.setBackgroundResource(R.layout.tables);

        String[] listeStrings = {"Value 1","Value 2"};

        lvListe.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,listeStrings));

    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的活动布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView 
          android:id="@+id/lvListe"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:layout_alignParentBottom="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

感谢有兴趣帮助我的人,我只是疯了......

亚当

Dev*_*red 11

尝试使用此布局代替您的RelativeLayout部分:

<RelativeLayout
  android:layout_height="fill_parent"
  android:layout_width="fill_parent">

  <FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@android:id/tabs"
    android:padding="5dp" />

  <TabWidget
    android:id="@android:id/tabs"
    android:layout_alignParentBottom="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

现在,你FrameLayout正在填充内部的整个空间RelativeLayout,因为RelativeLayout没有区别将项目放在彼此旁边LinearLayout,并允许重叠.我的调整告诉布局填充窗口顶部的窗口小部件之间的空间.

另一个注意事项RelativeLayout,项目的Z顺序由XML中的顺序决定,这就是为什么它TabWidget出现在FrameLayout.如果你颠倒了订单,TabWidget那就不可见了!

希望有所帮助!