2017-01-21 53 views
2

レイアウトは正しく表示されていませんが、2つのタブのみでSlidingTabsを作成しました。 Image 1は、私は常に取得し、出力されImage 2私は出力がTabLayoutのタイトルが正しく表示されない

出力

enter image description here

の予想される出力

enter image description here

layout.xml

を達成するために期待しています
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:id="@+id/pager_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/colorPrimary"> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/viewPager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/white" /> 
    </FrameLayout> 

    <test.com.example.view.SlidingTabLayout 
     android:id="@+id/sliding_tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" 
     android:paddingTop="?attr/actionBarSize" /> 

</FrameLayout> 
+1

try 'tabs.setDistributeEvenly(true);' –

答えて

2

あなたが依存関係で線の下に追加し、アプリのGradleのファイルでデザインサポートライブラリで利用可能なTabLayout

<android.support.design.widget.TabLayout 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/my_tab_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:elevation="6dp" 
     android:minHeight="?attr/actionBarSize" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:tabGravity="fill" 
     app:tabIndicatorColor="@android:color/white" 
     app:tabMaxWidth="0dp" 
     app:tabMode="fixed" 
     app:tabPaddingBottom="-1dp" 
     app:tabPaddingEnd="-1dp" 
     app:tabPaddingStart="-1dp" 
     app:tabPaddingTop="-1dp" /> 

を使用することができます。

compile 'com.android.support:design:24.2.1' 

Javaコードは次のようになります:

TabLayout myTabLayout = (TabLayout) findViewById(R.id.my_tab_layout); 
TabLayout.Tab tab1 = myTabLayout.newTab().setText("Details"); 
TabLayout.Tab tab2 = myTabLayout.newTab().setText("Cast"); 
myTabLayout.addTab(tab1); 
myTabLayout.addTab(tab2); 

これがあなたを助けてくれることを願っています。

関連する問題