Tabwidget 与我的活动内容重叠
在花了两天时间寻找答案后,我想就以下行为寻求帮助。
我正在尝试在 Android 上编写一个简单的 tabhost 应用程序,每个活动都有一个布局。 我设计了布局,以便选项卡小部件出现在屏幕底部。
在第一个选项卡上,我尝试插入一个简单的 2 行 ListView。我的问题是 ListView 位于底部,但它的一半隐藏在选项卡小部件后面。我想了解如何使我的 ListView 显示在选项卡小部件上方。
这是我的 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>
感谢任何热衷于帮助我的人,我简直要疯了......
亚当
after spending 2 solid days searching for an answer, I would like to ask for help about the following behaviour.
I'm trying to code a simple tabhost application on Android, with a layout per activity.
I've designed my layout so that the tabwidget appears at the bottom of the screen.
On the first tab, I'm trying to insert a simple 2 lines ListView. My problem is that the ListView is well on the bottom, but half of it is hidden behind the tabwidget. I would like to understand how to make my ListView to be displayed just above the tabwidget.
Here is my 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>
Here is my main app class :
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);
}
}
Here is my Activity code :
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));
}
}
Here is my layout for the activity :
<?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>
Thanks to anyone keen to help me I'm just going nuts....
Adam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
RelativeLayout
部分尝试使用此布局:现在,您的
FrameLayout
正在填充RelativeLayout
内的整个空间,如RelativeLayout< /code> 不会像
LinearLayout
那样将项目彼此相邻放置,并且允许重叠。我的调整告诉布局填充小部件与该布局顶部之间的空间。关于
RelativeLayout
的另一个注意事项,项目的 Z 顺序由 XML 中的顺序决定,这就是TabWidget
出现在FrameLayout
顶部的原因>。如果您颠倒了顺序,TabWidget
甚至将不可见!希望有帮助!
Try this layout instead for your
RelativeLayout
section:Right now, your
FrameLayout
is filling the entire space inside theRelativeLayout
, asRelativeLayout
makes no distinctions about placing items next to each other likeLinearLayout
does, and allows overlapping. My adjustment tells the layout to fill the space between the widget the the top of that layout.Another note about
RelativeLayout
, the Z-order of the items is determined by the order in XML, that's why theTabWidget
appears on top of theFrameLayout
. If you had reversed the order, theTabWidget
would not have even been visible!Hope that helps!