我尝试实现滚动标签,每个标签都有它的大小调整到它的内容的大小。
我尝试两种方法:动作条和TabHost。 在这两种情况下,我能够调整标签的大小。
为了实现这一点我在每个选项卡setLayoutProperites加入定标签后。 在这两种情况下,同样的做法。 的重量改变为0和宽度被设定为WRAP_CONTENT。 下面TabHost相关的例子。
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tabHost.getTabWidget().getChildTabViewAt(i).getLayoutParams();
params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
params.weight=0;
tabHost.getTabWidget().getChildTabViewAt(i).setLayoutParams(params);
我留下了相关的LinearLayout(LL)的大小问题。 LL的尺寸越大,其所有儿童的大小:
标签尺寸是按预期: 图像-1
LL标记,其大小是大(顶部),TabView的标记-它的大小是正确的(底部): 图像-2
对于TabHost情况下,布局XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:orientation="vertical">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<android.support.v4.view.ViewPager
android:id="@+id/tabHost_viewpager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</TabHost>