【问题标题】:I'm using material Design Fragment tabs layout我正在使用材料设计片段选项卡布局
【发布时间】:2017-11-27 07:54:25
【问题描述】:

目前我的问题是如何增加图片的宽度和高度?
下面我提到了标签布局片段的图像

请任何人帮助我。

【问题讨论】:

  • 你可以通过在标签中使用自定义视图来做到这一点
  • 你的图标大小是多少?
  • 如果你不是我的,请给我自定义视图的示例代码..@Manoj Kumar
  • 我的图标大小是 64*64 - SahadevRajput
  • 看看这个 tuts 解决你的问题androidhive.info/2015/09/…

标签: android performance android-layout android-fragments


【解决方案1】:

试试这个。

1.TabLayout 的宽度

public void setIndicator (TabLayout tabs,int leftDip,int rightDip){  
   Class<?> tabLayout = tabs.getClass();  
   Field tabStrip = null;  
   try {  
       tabStrip = tabLayout.getDeclaredField("mTabStrip");  
   } catch (NoSuchFieldException e) {  
       e.printStackTrace();  
   }  

   tabStrip.setAccessible(true);  
   LinearLayout llTab = null;  
   try {  
       llTab = (LinearLayout) tabStrip.get(tabs);  
   } catch (IllegalAccessException e) {  
       e.printStackTrace();  
   }  

   int left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, leftDip, Resources.getSystem().getDisplayMetrics());  
   int right = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rightDip, Resources.getSystem().getDisplayMetrics());  

   for (int i = 0; i < llTab.getChildCount(); i++) {  
       View child = llTab.getChildAt(i);  
       child.setPadding(0, 0, 0, 0);  
       LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1);  
       params.leftMargin = left;  
       params.rightMargin = right;  
       child.setLayoutParams(params);  
       child.invalidate();  
   }  
}

然后

tab.post(new Runnable() {  
       @Override  
       public void run() {  
           setIndicator(tab,60,60);  
       }  
});  


我的修改没有反射(应该设置自定义视图!)。

for (int i = 0; i < tabs.getTabCount(); i++) {
            TabLayout.Tab tab = tabs.getTabAt(i);
            if (tab != null) {
                View customView = tab.getCustomView();
                if (customView != null) {
                    View targetViewToApplyMargin = (View) customView.getParent();
                    ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) targetViewToApplyMargin.getLayoutParams();

                    layoutParams.rightMargin = totalTabMargin;
                    targetViewToApplyMargin.setLayoutParams(layoutParams);
                }
            }
 }

2.TabLayout 的身高

 app:tabIndicatorHeight="10dp"

还有java设置高度

 mTabLayout.setSelectedTabIndicatorHeight(10);

根据my answer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多