2016-09-14 2 views
0

Ich habe ein Problem mit Höheneffekt in meiner App (Schatten unter TabLayout genau), die kollabiert, nachdem ich meine App ausgeführt habe. Es ist im Vorschaumodus sichtbar, aber nicht auf meinem Gerät, weil es sich versteckt. Dies ist mein Code:Schatteneffekt (Elevation) wird ausgeblendet, nachdem App gestartet wurde

Hauptaktivität

<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> 

Hier ist Code von 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> 

Arten-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> 

Und hier ist mein Bildschirm während des Laufens App:

via GIPHY

ich einfach Schatten effectt erreichen wollen, die unter tablayout versteckt sich nicht vom Rest des Inhalts zu trennen. Ich teste es auf meinem Handy mit Android 6.0.1

+0

versuchen App: Elevation = "20dp". –

+0

keine Wirkung in meiner Situation. –

Antwort

0

Ich habe eine Lösung für mein Problem gefunden. Ich habe Relatives Layout mit Ansicht im Inneren erstellt, die Schatten imitiert. Das Hinzufügen dieser Codezeile nach TabLayout und vor dem Ende von AppBarLayout hat alles gelöst.

<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> 

Und hier ist voll Code von 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"/> 

schließlich nach 2 Tagen Brainstorming gelöst i es: D. Ich hoffe, dass dies in Zukunft jemandem helfen wird.

Verwandte Themen