2015-10-17 17 views
5

Tùy chỉnh luôn được căn giữa trong Tablayout. Tablayout như sau. Làm cách nào để có được không gian đầy đủ cho cha mẹ, ví dụ: TabView.Chế độ xem tùy chỉnh Tablayout thiết kế Android không thể đối sánh với cha mẹ

<android.support.design.widget.TabLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/tablayout" 
    android:layout_width="match_parent" 
    app:tabPaddingStart="0dp" 
    app:tabPaddingEnd="0dp" 
    android:layout_height="90dp"> 
</android.support.design.widget.TabLayout> 

Thêm một TextView như dưới đây

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/holo_purple" 
    android:gravity="center_horizontal"> 

<TextView 
    android:text="Hello !" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 
</LinearLayout> 

Nhưng tiếc là nó luôn luôn làm trung tâm và không bao giờ có được đầy đủ các không gian. Vấn đề là tôi không thể cung cấp dải phân cách giữa các tab vì nó luôn ở giữa.

đang

Java cho tab thêm:

TabLayout v = (TabLayout)findViewById(R.id.tablayout); 
    TabLayout.Tab tab = v.newTab(); 
    tab.setCustomView(R.layout.content_main); 
    v.addTab(tab); 
    tab = v.newTab(); 
    tab.setCustomView(R.layout.content_main); 
    v.addTab(tab); 
    tab = v.newTab(); 
    tab.setCustomView(R.layout.content_main); 
    v.addTab(tab) 

I'v chia sẻ hình ảnh @http://i60.tinypic.com/11cdvyf.jpg

Trả lời

7

Bug được đăng ký ở đây: https://code.google.com/p/android/issues/detail?id=190429

Mặc dù bạn có thể workaround nó bằng cách bơm diện tùy chỉnh của bạn và sau đó áp dụng các thông số bố cục theo cách thủ công:

View v = LayoutInflater.from(this).inflate(R.layout.view_goal_tab_active, null); 
TextView tv = (TextView)v.findViewById(R.id.goal_tab_active_tv); 
tv.setSelected(true); 
v.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 
mTabs.getTabAt(0).setCustomView(v); 
Các vấn đề liên quan