2016-05-21 17 views
5

Trong ứng dụng của tôi, tôi đang làm việc tablayout. tất cả mọi thứ làm việc tốt nhưng tôi muốn văn bản tablayout và dòng chỉ số cả hai nên cùng kích thước.Cách tạo cùng chiều rộng của chỉ báo Tablayout và văn bản

nhưng chiều rộng chỉ báo trái và phải lấy thêm không gian. làm thế nào để loại bỏ thêm không gian hoặc làm cho nó cả hai chiều rộng bằng nhau.

làm cần thiết

nhờ

+0

bài gì bạn có 'tried'? – Ironman

+0

tab.setcustomview hoạt động nhưng tôi đang gặp sự cố khác. là có bất kỳ thẻ gốc để giảm không gian. – Jeeva

+1

tôi muốn giảm độ rộng của chỉ số. – Jeeva

Trả lời

0

tôi tìm thấy một giải pháp từ http://blog.csdn.net/u013134391/article/details/70833903

public void reflex(final TabLayout tabLayout){ 
    tabLayout.post(new Runnable() { 
     @Override 
     public void run() { 
      try { 
       LinearLayout mTabStrip = (LinearLayout) tabLayout.getChildAt(0); 

       int dp10 = dip2px(tabLayout.getContext(), 10); 

       for (int i = 0; i < mTabStrip.getChildCount(); i++) { 
        View tabView = mTabStrip.getChildAt(i); 


        Field mTextViewField = tabView.getClass().getDeclaredField("mTextView"); 
        mTextViewField.setAccessible(true); 

        TextView mTextView = (TextView) mTextViewField.get(tabView); 

        tabView.setPadding(0, 0, 0, 0); 

        int width = 0; 
        width = mTextView.getWidth(); 
        if (width == 0) { 
         mTextView.measure(0, 0); 
         width = mTextView.getMeasuredWidth(); 
        } 


        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tabView.getLayoutParams(); 
        params.width = width ; 
        params.leftMargin = dp10; 
        params.rightMargin = dp10; 
        tabView.setLayoutParams(params); 

        tabView.invalidate(); 
       } 

      } catch (NoSuchFieldException e) { 
       e.printStackTrace(); 
      } catch (IllegalAccessException e) { 
       e.printStackTrace(); 
      } 
     } 
    }); 

} 
Các vấn đề liên quan