在花了两天时间寻找答案之后,我想就以下行为寻求帮助。
我正在尝试在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>
这是我的主要应用类:
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);
}
}
这是我的活动代码:
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));
}
}
以下是我的活动布局:
<?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>
感谢有兴趣帮助我的人,我只是疯了......
亚当
答案 0 :(得分: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>
现在,FrameLayout
填充了RelativeLayout
内的整个空间,因为RelativeLayout
没有像LinearLayout
那样区分彼此相邻的项目,并且允许重叠。我的调整告诉布局填充窗口小部件之间的空间。
关于RelativeLayout
的另一个注释,项目的Z顺序由XML中的顺序决定,这就是TabWidget
出现在FrameLayout
之上的原因。如果你颠倒了订单,TabWidget
甚至都不可见了!
希望有所帮助!