【问题标题】:Android TabLayout fixed mode but different weightsAndroid TabLayout 固定模式但权重不同
【发布时间】:2016-04-02 00:05:40
【问题描述】:

我有 4 个标签,其中一个的大小是其他标签的两倍,因此权重为:20% 40% 20% 20%

但是当我使用 TabLayout(来自 android 设计支持库)将模式设置为 fixed 时,我不得不对所有人使用相同的权重!这是他们应用宽度的源代码部分:

private void updateTabViewLayoutParams(LinearLayout.LayoutParams lp) {
    if (mMode == MODE_FIXED && mTabGravity == GRAVITY_FILL) {
        lp.width = 0;
        lp.weight = 1;
    } else {
        lp.width = LinearLayout.LayoutParams.WRAP_CONTENT;
        lp.weight = 0;
    }
}

但我需要不同的权重,以适应屏幕宽度。有什么方法可以应用我自己的重量?

【问题讨论】:

    标签: android android-design-library android-tablayout androiddesignsupport


    【解决方案1】:
        //SlidingTabStrip in TabLayout
        ViewGroup slidingTabStrip = (ViewGroup)mTablayout.getChildAt(0);
        //second tab in SlidingTabStrip
        View tab1 = slidingTabStrip.getChildAt(1);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) tab1.getLayoutParams();
        layoutParams.weight = 2;
        tab1.setLayoutParams(layoutParams);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-24
      • 2016-11-26
      • 2016-08-22
      相关资源
      最近更新 更多