【问题标题】:Stretch swipe tabs width to fill whole space拉伸滑动标签宽度以填充整个空间
【发布时间】:2015-02-06 09:57:57
【问题描述】:

在使用支持库时,是否有任何方法可以在纵向模式下的 Android Swipe Tabs 中拉伸标签宽度(如果可能,还可以更改它们的高度)? 当前设置:

    <item name="android:actionBarSize">90dp</item>
    <item name="actionBarSize">90dp</item>
    <item name="actionBarTabStyle">@style/MyActionBarTab</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarTab</item>

<style name="MyActionBarTab"
    parent="@style/Widget.AppCompat.ActionBar.TabView">
    <item name="android:height">90dp</item>
</style>

样式没有帮助。还使用最小宽度和高度参数动态创建自定义视图:

    // Tab B
    LinearLayout lila_b = new LinearLayout(this);
    lila_b.setMinimumHeight(300);
    lila_b.setMinimumHeight(300);
    lila_b.setBackgroundColor(Color.parseColor("#ffc600"));
    lila_b.setOrientation(LinearLayout.HORIZONTAL);
    lila_b.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
    ImageView imvi_b = new ImageView(this);
    imvi_b.setImageResource(R.drawable.tabs_history);
    imvi_b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT));
    imvi_b.setAdjustViewBounds(true);
    lila_b.addView(imvi_b);
    TextView tevi_b = new TextView(this);
    tevi_b.setText(getString(R.string.main_history));
    tevi_b.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
    tevi_b.setTextColor(Color.WHITE);
    tevi_b.setGravity(Gravity.CENTER);
    lila_b.addView(tevi_b);
    Tab newTab = getSupportActionBar().newTab().setTabListener(this);
    newTab.setCustomView(lila);
    getSupportActionBar().addTab(historyTab);

没有帮助。 即使这样:

    final View tabView = actionBar.getTabAt(0).getCustomView();
    final View tabContainerView = (View) tabView.getParent();
    tabView.setMinimumHeight(300);
    tabContainerView.setMinimumHeight(300);

什么都没做。我没主意了。 任何解决方案如何扩展这些选项卡?

附:问题是关于 Google 支持库和滑动标签的。我目前对使用第三方库不感兴趣...

【问题讨论】:

  • 好的,在我的尺寸中添加 1000dp 实际上确实有助于宽度,它们最终在整个屏幕上都显示出来了。身高呢?

标签: android tabs height size width


【解决方案1】:

好的。最后! 简单添加:

<dimen name="abc_action_bar_stacked_tab_max_width">1000dp</dimen>
<dimen name="abc_action_bar_stacked_max_height">408dp</dimen>

在维度中强制标签水平和垂直拉伸。最后有两个选项卡,它们在平板电脑上从左到右填充所有空间。这正是我所需要的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多