【发布时间】:2012-05-07 21:55:54
【问题描述】:
我确定它需要一个简单的标志,但我没有找到正确的标志,我花了至少 2 个小时才找到正确的解决方案。希望能得到各位大师的帮助。 我正在尝试使用 fragmentActivity 创建一个两个选项卡布局。我想为每个选项卡提供 50% 的屏幕空间。我能够做到这一点(见附加的屏幕截图)下一个障碍是我想要标签页眉,例如财务与黑色 bkg 应占 50%,其他与 gary bkg 应占剩余 50%。
我希望我的问题很清楚。 :-)
attaching my 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"
android:background="#EFEFEF" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@+id/financial"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"
android:tag="@string/financial" />
<FrameLayout
android:id="@+id/other"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:tag="@string/others" />
</FrameLayout>
</RelativeLayout>
</TabHost>
**The calling xml would be**
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1" >
</ListView>
<fragment
class="com.......android.activity.AccountsTab"
android:id="@+id/tabs_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"/>
</RelativeLayout>
添加tab.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="@dimen/tab_height"
android:background="@drawable/tab_selector"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="@dimen/tab_padding"
android:weightSum="0.5" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_horizontal|center_vertical"
android:textColor="@drawable/tab_text_selector"
android:textSize="@dimen/text_default"
android:textStyle="italic" />
</RelativeLayout>
【问题讨论】:
-
你的意思是,两个标签的大小应该相同?
-
@Raghav 是的,两者都应该占据可用的屏幕宽度。我还想在每个选项卡的左侧设置图标。注意:图标会有不同的动作。我添加了有问题的 tab.xml。
标签: java android xml android-fragments