Java 片段选项卡标题/标签大小
我确信它需要一个简单的标志,但我没有找到正确的标志,至少花了2个小时来找到正确的解决方案。希望能得到你上师的帮助。 我正在尝试使用fragmentActivity创建两个选项卡的布局。我想给每个选项卡50%的屏幕空间。我能做到这一点,请看附带的屏幕截图。下一个障碍是我希望选项卡标题,例如,黑色bkg的财务应占50%,gary bkg的其他人应占剩余的50%。 我希望我的问题清楚-Java 片段选项卡标题/标签大小,java,android,xml,android-fragments,Java,Android,Xml,Android Fragments,我确信它需要一个简单的标志,但我没有找到正确的标志,至少花了2个小时来找到正确的解决方案。希望能得到你上师的帮助。 我正在尝试使用fragmentActivity创建两个选项卡的布局。我想给每个选项卡50%的屏幕空间。我能做到这一点,请看附带的屏幕截图。下一个障碍是我希望选项卡标题,例如,黑色bkg的财务应占50%,gary bkg的其他人应占剩余的50%。 我希望我的问题清楚- attaching my xml <?xml version="1.0" encoding="utf-8"?
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>
我认为你应该这样做
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
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"
>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>
</LinearLayout>
使用此功能,您可以添加任意多个选项卡
希望您想要这个。您的意思是,两个选项卡的大小应该相同?@Raghav是的,并且两个选项卡都应该占用可用的屏幕宽度。我还想在每个选项卡的左侧设置图标。注意:图标将有不同的操作。我已经添加了问题中的tab.xml。谢谢你的回答,我用了其他方法,但我尝试了,并且为我工作。我会记下答案。