2016-01-08 15 views
10

Witam potrzebuję dodać cień pod układem karty (jak w skypie).Jak dodać cień dolny do układu tabulatora

shadow_skype

Moja aktywność xml:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <android.support.v7.widget.Toolbar xmlns:local="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="?attr/actionBarSize" 
     android:background="@color/splashGreenTop" 
     local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     local:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
    <android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout" 
     android:layout_below="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:elevation="0dp" 
     android:minHeight="?attr/actionBarSize" /> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_below="@+id/tab_layout" 
     android:id="@+id/tabContainer" 
     android:layout_height="match_parent" /> 
</RelativeLayout> 

kiedy dodać android:elevation="10dp" do Tablayout, cień dodano dolny i górny .. Muszę tylko dno. Zobacz obraz ...

enter image description here

Jak mogę to zrobić? Z góry dzięki.

+0

http://stackoverflow.com/ pytania/26572048/elewacja-na-android-lollipop-nie działa –

Odpowiedz

20

Po prostu dodaj elewację do swojego Tablayout (0dp - 25dp). Zapoznaj się z wytycznymi material design, aby uzyskać więcej informacji na temat elewacji.

android:elevation="10dp" 

EDIT:
dodać go zarówno do tablayout i pasek narzędzi

<android.support.v7.widget.Toolbar xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?attr/actionBarSize" 
    android:background="@color/splashGreenTop" 
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    android:elevation="10dp" /> 
<android.support.design.widget.TabLayout 
    android:id="@+id/tab_layout" 
    android:layout_below="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?attr/colorPrimary" 
    android:minHeight="?attr/actionBarSize" 
    android:elevation="10dp"/> 
+1

@puko jak już wspomniałem dodaj elewację do twojego 'ToolBar' też –

+0

@puko check zrobiłem edycję –

+0

świetna !! dzięki – puko

1

próby dodania prostej między TabLayout i Toolbar. Ustaw tło dla tego widoku jako gradient, który naśladuje cień.

Shadow.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
     android:startColor="#20000000" 
     android:endColor="@android:color/transparent" 
     android:angle="90"> 
    </gradient> 
</shape> 
2

Tutaj jest oszukać Można użyć widoku poniżej paska narzędzi i dostosować go jak jak u wymagać

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <android.support.v7.widget.Toolbar xmlns:local="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="?attr/actionBarSize" 
     android:background="@color/splashGreenTop" 
     local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     local:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
    <android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout" 
     android:layout_below="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:elevation="0dp" 
     android:minHeight="?attr/actionBarSize" /> 

     <View 
     android:layout_width="match_parent" 
     android:layout_height="5dp" 
     android:layout_below="@+id/tab_layout" 
     android:background="@drawable/toolbar_dropshadow" /> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_below="@+id/tab_layout" 
     android:id="@+id/tabContainer" 
     android:layout_height="match_parent" /> 
</RelativeLayout> 

następnie utworzyć xml w rozciągliwej tak

@drawable/toolbar_dropshadow: 
<?xml version="1.0" encoding="utf-8"?> 
<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"/> 
</shape> 

Zmień stan kolor rt i kolor końcowy, które chcesz zastosować:

0

Tu jest rzeczywiście bardzo proste rozwiązanie: Wystarczy umieścić pasek i TabLayout wewnątrz z AppBarLayout. Na przykład:

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ToolbarTheme" 
     app:titleTextAppearance="@style/ThemeOverlay.AppCompat.ActionBar" 
     android:background="@color/colorPrimary"/> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> 
</android.support.design.widget.AppBarLayout> 

Działa to doskonale dla mnie i jest to powszechny sposób połączyć App-/Toolbar i TabLayout.

3

Możesz dodać TabLayout jako dziecko w AppBarLayout który ma cienia domyślnie lub można określić głębokość cień przez aplikacji Wysokość = „XDP”

<android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:elevation="xdp"> 

     <android.support.v7.widget.Toolbar 
     ... 
     /> 

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

    </android.support.design.widget.AppBarLayout> 
Powiązane problemy