簡體   English   中英

Android使用DrawerLayout刪除自定義工具欄和陰影之間的空間

[英]Android remove space between custom Toolbar and shadow with DrawerLayout

我正在使用Linearlayout像android Toolbar一樣, Linearlayout我設置了自定義陰影,不幸的是,在打開DrawerLayout之后,自定義工具欄和抽屜布局之間的空間很小,我無法解決此問題

當前問題:

在此處輸入圖片說明

正確的視圖:

在此處輸入圖片說明

我的自定義LinearLayout作為帶有application_toolbar名稱的工具欄:

    <?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:layout_width="fill_parent"
        android:layout_height="52dp"
        android:background="#eaeaea"
        android:gravity="center">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" />

        <pishguy.ir.asrebidree.Widgets.TextViewStyle
            android:layout_width="100dp"
            android:layout_height="fill_parent"
            app:fonttype="mjbeirut"
            android:text="@string/app_name"
            android:textSize="20sp"
            android:textColor="#737373"
            android:gravity="right"
            android:layout_marginRight="5dp"
            android:paddingTop="7dp" />
    </LinearLayout>

活動主,帶有drawerLayout和自定義工具欄:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <!-- CUSTOM TOOLBAR -->
    <include
        android:id="@+id/toolbar"
        layout="@layout/application_toolbar" />

    <!-- TOOLBAR SHADOW -->
    <View
        android:layout_width="fill_parent"
        android:layout_height="5dp"
        android:background="@drawable/toolbar_dropshadow" />

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_items"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="2dp">

        </android.support.v7.widget.RecyclerView>
        ...
    </android.support.v4.widget.DrawerLayout>

</LinearLayout>

工具欄陰影:

<?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="#50949494"
        android:angle="90"/>
</shape>

將Drawer布局更改為具有marginTop =“-5dp”。 基本上因為它是線性布局,所以總是在陰影下。 -5dp會將其移到陰影下方。

將父布局更改為RelativeLayout而不是LinearLayout。 然后,您可以將抽屜微調到正下方。 確保在抽屜之后聲明陰影以使其最后繪制並在抽屜頂部。

使用DrawerLayout將活動主布局更改為以下內容,您將獲得所需的結果。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <!-- CUSTOM TOOLBAR -->
    <include
        android:id="@+id/toolbar"
        layout="@layout/confirm_toolbar" />


    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_below="@+id/toolbar"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_items"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="2dp">

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

    </android.support.v4.widget.DrawerLayout>

   <!-- TOOLBAR SHADOW -->

    <View
        android:layout_width="fill_parent"
        android:layout_below="@+id/toolbar"
        android:layout_height="5dp"
        android:background="@drawable/toolbar_dropshadow" />

</RelativeLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM