0

Activity에 bottomBar 및 각 항목을 조각으로 포함하려는 응용 프로그램을 작성 중입니다. 첫 번째 조각에는 뷰 페이지가 있어야합니다. TabLayout과 툴바의 높이가 같지 않다는 점을 제외하고는 모두 잘 작동합니다.Tablayout과 툴바가 동일한 높이가 아님

enter image description here

내 활동 레이아웃은 다음과 같습니다 :

문제는

<android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <include 
      android:id="@+id/toolbar" 
      layout="@layout/toolbar_top" /> 
    </android.support.design.widget.AppBarLayout> 

내 toolbarTop 레이아웃 :

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:theme="@style/Base.ThemeOverlay.AppCompat.Dark" 
    android:id="@+id/topBar" 
    android:background="@color/colorPrimary"> 
</android.support.v7.widget.Toolbar> 

내 tablayout 조각 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 

    android:layout_marginBottom="?android:attr/actionBarSize" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     app:tabMaxWidth="0dp" 
     app:tabGravity="fill" 
     app:tabMode="fixed" 
     android:elevation="6dp" 
     android:layout_height="?android:attr/actionBarSize" 
     android:background="@color/colorPrimary" /> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     app:layout_scrollFlags="scroll|enterAlways|snap" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

나는 this answer을 시도했지만 성공하지 못했습니다. 모든 파편에 tablayout이 있기 때문에 Applaylayout에 tablayout을 넣을 수는 없습니다 (문제를 해결 함).

이 문제를 해결하는 다른 방법은 있습니까?

+0

'TabLayout'에서이 속성을 설정합니다 : android : fillViewport = "false"'. – Ironman

+0

그것은 작동하지 않았다 ... 여전히 동일한 결과가 –

답변

0

이렇게하려면 AppbarLayout에 포함해야합니다. TabLayout을 툴바 아래 toolbarTop.xml 파일에 추가하십시오.

+0

이라면 모든 조각에 Tablayout이 있음 –

+0

예, 다른 조각에서 tablayout을 숨길 수 있습니다. getActivity(). findViewById (R.id.tab_layout) .setVisibility (View.GONE); –

+0

그리고 fragment에서 viewpager로 tablayout을 설정하는 방법은 무엇입니까? –