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