2

여러분! 네비게이션 서랍이있는 액티비티 내의 FrameLayout 컨테이너에 조각이 있습니다. 조각에 TabLayout이 있습니다. 그리고 알 수 있듯이 액티비티의 툴바는 조각의 TabLayout에 그림자를 떨어 뜨리는 문제점이 있습니다. 단편에서 액세스 할 수 없기 때문에 활동의 AppBar 레이아웃에 TabLayout을 배치하고 싶지 않습니다. 또한 다른 곳에서는 그 TabLayout이 필요하지 않습니다.Toobar가 TabLayout에 그림자를 드리운다

Screenshot

이 내 activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 

<include 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<android.support.design.widget.NavigationView 
    android:id="@+id/mainNavigationView" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

입니다 그리고 이것은 app_bar_main.xml

입니다
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/loginToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways|snap" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

    <FrameLayout 
     android:id="@+id/mainFragmentContainer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</LinearLayout> 

이3210

나는 또한 당신이 어떤 생각을 가지고 있습니까 내가 ViewPager

내 조각에서 목록을 스크롤 할 때 도구 모음 숨기려 fragment_by_day_schedule.xml

<?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" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical"> 

<android.support.design.widget.TabLayout 
    android:id="@+id/byDayTabLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:tabBackground="?attr/colorPrimary" 
    app:tabMode="scrollable" /> 

<android.support.v4.view.ViewPager 
    android:id="@+id/byDayViewPager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

</LinearLayout> 

입니다 나는 어떻게 그것을 얻을 수 있습니까?

+0

당신이 당신이 도구 모음 안에 넣어 경우 조각에서 tablayout에 액세스 할 수 없습니다 생각하게? 솔직히 말해서 툴바 안에 탭이있는 것이 훨씬 좋고 훨씬 더 널리 이해되는 패턴이라고 생각합니다. 또한 뷰 페이지 위로 이동하면서 툴바를 숨기는 효과를 얻을 수 있습니다. – gaara87

+0

내 대답을 다시 확인하십시오. 두 번째 질문을 업데이트했습니다. –

답변

3

사용하십시오. 내 프로젝트에서 작동합니다.

ViewCompat.setElevation(mAppBarLayout, 0); 

두 번째 질문은 툴바를 숨기는 방법입니다. 부모 레이아웃 선형 레이아웃을 레이아웃으로 변경하십시오.

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/loginToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways|snap" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

    <FrameLayout 
     android:id="@+id/mainFragmentContainer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</android.support.design.widget.CoordinatorLayout> 

이 후에 툴바가 숨겨져 있어야 할 때 안드로이드에게 알려야합니다. 스크롤 할 수있는보기를 말해야합니다. ViewPager에 app:layout_behavior="@string/appbar_scrolling_view_behavior"을 추가하십시오. 지원 라이브러리 v24.0.0에서

<?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" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical"> 

<android.support.design.widget.TabLayout 
    android:id="@+id/byDayTabLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:tabBackground="?attr/colorPrimary" 
    app:tabMode="scrollable" /> 

<android.support.v4.view.ViewPager 
    android:id="@+id/byDayViewPager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 
</LinearLayout> 
+0

) 고마워요. 내가 시도해 볼게. – frozzyk

+0

ViewCompat.setElevation()에 대해 전혀 알지 못했습니다. –

1

모든 항목의 높이가 같아야합니다.

+0

pre-lollipop에서 작동하지 않기 때문에'elevation'을 사용하고 싶지 않습니다. – frozzyk

+3

나는 이것이 /하고 싶지 않다는 것을 확신하지 못합니다. 그림자는 표고에서 그려집니다. 그림자를 원하지 않는다면 높이를 0으로 지정해야합니다. 그러나 이것은 디자인을 평평하게하고 표면을 사용하는 재질 디자인 언어 패턴과 모순됩니다. – apelsoczi

+0

사전 롤리팝에 시도했지만 작동하지만 API 21 이상에서는 작동하지 않습니다. 효과 없음 ( – frozzyk

1

AppBarLayout는 StateListAnimator를 사용합니다. appBayLayout.setElevation(0) 설정은이 새 버전에서 사용하면 아무 효과가 없습니다.

대신 Build.VERSION.SDK_INT >= 21에 대해 다음과 같이 StateListAnimator 0으로 고도를 설정하려고 :

StateListAnimator stateListAnimator = new StateListAnimator(); 
stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0)); 
appBarLayout.setStateListAnimator(stateListAnimator); 
+1

감사합니다! 시도 할 것입니다. – frozzyk

1

를 지원 라이브러리에서 v24.0.0 AppBarLayout는 세트 상승에 대한 StateListAnimator를 사용합니다. 사전 24.0.0 그냥 애니메이터가 null로 설정과 같은 동작을 얻을로 전화 setElevation() :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
    appbarLayout.setStateListAnimator(null); 
} 

ViewCompat.setElevation(appbarLayout, 0);