2016-09-14 65 views
0

我在運行我的應用程序後崩潰的應用程序中的海拔效果(正好在TabLayout下的陰影)時出現問題。它在預覽模式下可見,但不會在我的設備上顯示,因爲它隱藏了。這是我的代碼:應用程序啓動後陰影效果(海拔)隱藏

主要活動

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/white" 
android:clipToPadding="false"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar_material_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/toolbar1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" > 

     <ImageView 
      android:id="@+id/header" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/background_portrait" 
      android:fitsSystemWindows="true" 
      android:scaleType="centerCrop" 
      app:layout_collapseMode="parallax" />` 

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

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabGravity="fill" 
     android:elevation="20dp" 
     app:tabTextAppearance="@style/MineCustomTabText" 
     /> 

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

<android.support.v4.view.ViewPager 
    android:id="@+id/viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    /></android.support.design.widget.CoordinatorLayout> 

這裏是styles.xml的代碼

<resources> 

<style name="MyMaterialTheme" parent="MyMaterialTheme.Base"> 

</style> 

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="windowNoTitle">true</item> 
    <item name="windowActionBar">false</item> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="colorControlNormal">@color/editTextIndigo</item> 
    <item name="colorControlActivated">@color/editTextPink</item> 
</style> 

<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title"> 
    <item name="android:textSize">16sp</item> 
    <item name="android:textAllCaps">true</item> 
</style> 
<style name="MineCustomTabText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"> 
    <item name="android:textSize">13sp</item> 
    <item name="android:textAllCaps">true</item> 
    <item name="android:textColor">@android:color/white</item> 
</style> 

風格,v21.xml

<resources> 

<style name="MyMaterialTheme" parent="MyMaterialTheme.Base"> 
    <item name="android:windowContentTransitions">true</item> 
    <item name="android:windowAllowEnterTransitionOverlap">true</item> 
    <item name="android:windowAllowReturnTransitionOverlap">true</item> 
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item> 
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item> 
</style> 

這裏是我的屏幕上,同時運行的應用程序:

via GIPHY

我想要實現沒有根據tablayout隱藏與內容的其餘部分單獨簡單的陰影effectt。我正在使用android 6.0.1在我的手機上測試它。

+0

try app:elevation =「20dp」。 –

+0

對我的情況沒有影響。 –

回答

0

我找到了解決我的問題的方法。我已經創建了內部視圖的相對佈局,模仿陰影。在TabLayout之後和AppBarLayout結束之前添加這行代碼解決了所有問題。

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_anchor="@id/tabs" 
     app:layout_anchorGravity="bottom" 
     android:background="@android:color/white"> 


     <View 
      android:layout_width="match_parent" 
      android:layout_height="4dp" 
      android:layout_alignParentBottom="true" 
      android:background="@drawable/tablayout_shadow" 
      /> 
    </RelativeLayout> 

這裏是main_activity.xml的全碼

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/white" 
android:clipToPadding="false"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar_material_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/toolbar1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" > 

     <ImageView 
      android:id="@+id/header" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/background_portrait" 
      android:fitsSystemWindows="true" 
      android:scaleType="centerCrop" 
      app:layout_collapseMode="parallax" /> 



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



    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabGravity="fill" 
     android:elevation="20dp" 
     app:tabTextAppearance="@style/MineCustomTabText" 
     /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_anchor="@id/tabs" 
     app:layout_anchorGravity="bottom" 
     android:background="@android:color/white"> 


     <View 
      android:layout_width="match_parent" 
      android:layout_height="4dp" 
      android:layout_alignParentBottom="true" 
      android:background="@drawable/toolbar_shadow" 
      /> 
    </RelativeLayout> 
</android.support.design.widget.AppBarLayout> 


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

tablayout_shadow.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
<gradient 
    android:startColor="@android:color/transparent" 
    android:endColor="#88333333" 
    android:angle="90"/> 

最後經過頭腦風暴2天我解決它:d。我希望這將有助於未來的人。