我见过this programmatic solution但我想知道在XML文件中如何做到这一点..我的目标是让一组选项卡最多使用所有可用的屏幕宽度。目前我无法看到如何做到这一点。将tabhost的layout_width设置为fill_parent并不能解决问题。如何在XML布局中设置android选项卡的宽度?
0
A
回答
2
当我使用标签时,我通常只是通过将android可见性设置为消失来隐藏tabwidget标签。
按钮并将其添加到充当标签按钮像
<?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">
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="0dip"
android:layout_weight="1.0"/>
<FrameLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="64dip">
<Button android:layout_height="fill_parent" android:layout_width="0dip"
android:layout_weight="1.0"
android:background="@drawable/ic_tab_artists"
android:id="@+id/artist_id" android:onClick="tabHandler"/>
<Button android:layout_height="fill_parent" android:layout_width="0dip"
android:layout_weight="1.0"
android:background="@drawable/ic_tab_artists"
android:id="@+id/album_id" android:onClick="tabHandler"/>
<Button android:layout_height="fill_parent" android:layout_width="0dip"
android:layout_weight="1.0"
android:background="@drawable/ic_tab_artists"
android:id="@+id/song_id" android:onClick="tabHandler"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
,我添加一个按钮单击处理
public void tabHandler(View target){
artistButton.setSelected(false);
albumButton.setSelected(false);
songButton.setSelected(false);
if(target.getId() == R.id.artist_id){
tabHost.setCurrentTab(0);
artistButton.setSelected(true);
} else if(target.getId() == R.id.album_id){
tabHost.setCurrentTab(1);
albumButton.setSelected(true);
} else if(target.getId() == R.id.song_id){
tabHost.setCurrentTab(2);
songButton.setSelected(true);
}
}
1
我增加了一个水平滚动条,并设置android:fillViewport="true"
。
相关问题
- 1. 选项卡中的XML布局android(tabhost)
- 2. 如何隐藏Android选项卡布局中的选项卡?
- 3. 如何设置FloatingActionButton在选项卡布局中的屏幕上?
- 4. Android动态设置textview布局宽度
- 5. 如何将布局设置为QTabWidget中的选项卡?
- 6. Android Tab选项卡布局
- 7. ActionBar Sherlock选项卡太短//如何设置选项卡的宽度
- 8. 如何为Android的PagerSlidingTabStrip中的所有选项卡设置相同的宽度?
- 9. 如何设置窗口编辑器选项卡的宽度以均匀分布?
- 10. 如何在XML布局中添加选项卡和工具栏
- 11. Android中的选项卡布局中的进度对话框
- 12. 从SD卡中设置xml文件作为Android中的布局
- 13. 在Android界面中设置半fill_parent布局宽度
- 14. Android的线性布局的高度和宽度没有设置
- 15. 设置android的相对布局的高度和宽度
- 16. 在Android中,如何设置ListView项目的高度和宽度?
- 17. 如何确定选项卡中片段的XML布局?
- 18. 如何在选择中设置选项的宽度?
- 19. Android布局如何设置特定的固定布局高度
- 20. Android中设置表布局列的宽度相等
- 21. 如何为电视设置任何布局(宽度,高度)?
- 22. 如何设置CSS网格布局中列的最大宽度?
- 23. 如何在Android中实现此选项卡式布局?
- 24. 如何在Android 4.0中创建选项卡式布局?
- 25. 如何在android选项卡布局中提供溢出分页?
- 26. 如何在Android布局中创建一个选项卡视图
- 27. 如何在选项卡式布局中显示Android Gridview
- 28. 设置宽度=设备宽度视打破布局
- 29. Galaxy选项卡的布局设计
- 30. Android布局设计 - 如何在xml中获取屏幕高度(布局)