2016-05-04 8 views
-1

アプリと同じようにTabLayoutを実装します。Google PlayミュージックアプリのようなカスタムTabLayout

  • 肖像(Google Playミュージック): enter image description here
  • 風景(Googleの音楽を再生する):TabLayoutを処理する

    <android.support.design.widget.TabLayout 
         android:id="@+id/tab_layout" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content"> 
    
        </android.support.design.widget.TabLayout> 
    

    マイコード: enter image description here

は、これが私のレイアウトであります:

private void init() { 
    mTabLayout = (TabLayout) findViewById(R.id.tab_layout); 
    mTabLayout.addTab(mTabLayout.newTab().setText("Category 1")); 
    mTabLayout.addTab(mTabLayout.newTab().setText("Category 2")); 
    mTabLayout.addTab(mTabLayout.newTab().setText("Category 3")); 
    mTabLayout.addTab(mTabLayout.newTab().setText("Category 4")); 
    mTabLayout.addTab(mTabLayout.newTab().setText("Category 5")); 
    mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); 
} 

しかし、結果はTabLayoutは左のマージンを持ってdoensn'tです:

  • 肖像(私の例):: enter image description here
  • 風景(私の例): enter image description here

Iこれを試してくださいarticleしかし、結果は期待どおりではありません。上記のように、Google PlayミュージックアプリのようなカスタムTabLayoutはどうすればよいですか?

答えて

3

android:marginLeftをTabLayoutに使用する必要があります。

<android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="16dp"> 

    </android.support.design.widget.TabLayout> 

、縦と横方向に異なるマージンを持っている値/ dimens.xmlで別の値を使用して値-ランド/ dimens.xmlする

更新:

マージンを使用して、スペースを作ります、タブをスクロールしてもだから私は期待していないとして、私はそれが左画面上のスペースを作るスクロールしたときに、marinLeftまたはpaddingLeftを追加clipToPadding="false"

<android.support.design.widget.TabLayout 
      android:id="@+id/tab_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="16dp" 
      android:clipToPadding="false"> 

     </android.support.design.widget.TabLayout> 
+0

で、パディングを使用して試してみました。 –

+0

は答えを更新しました: – Bob

+0

あなたの答えは、アンドロイド:paddingLeft = "16dp"とandroid:clipToPadding = "false">でうまくいきました。ありがとうございました。 –

関連する問題