android - 高程不适用于 LinearLayout

标签 android android-layout material-design

在寻找解决方案后,我没有找到任何可以解决我的问题的方法。

我有一些高度,这会在我的应用程序的很大一部分上产生阴影。
但是在特定的地方,我无法使其工作。
(就是我在下图中放了一个箭头的地方)

enter image description here

工具栏下方的白色区域是一个Fragment,它显示了一个LinearLayout

布局:

<LinearLayout
    android:id="@+id/panelAddress"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/button_flat_white"
    android:elevation="10dp"
    android:orientation="vertical"
    android:padding="20dp"
    >  
//some content
</LinearLayout>

fragment 的父级:

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawerLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            android:id="@+id/custom_toolbar"
            layout="@layout/toolbar"/>

        <RelativeLayout
            android:id="@+id/mapLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <fragment
                android:id="@+id/map"
                class="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

            <FrameLayout
                android:id="@+id/fragment_container_top"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                />

            <FrameLayout
                android:id="@+id/fragment_container_bottom"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"/>

        </RelativeLayout>

    </LinearLayout>

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

你知道为什么我没有得到提升吗?

最佳答案

如此处所述https://stackoverflow.com/a/27518160/2481494绘制阴影有几个要求:

  • 空格用于父 View 组中的阴影。正如bleeding182 提到的,填充会导致阴影被剪裁:

    (Do NOT use a padding. A padding on the framelayout will also cut the shadow off)

    但是,可以使用父级中的 android:clipToPadding="false" 来解决此问题。

  • 提升的 View 需要有背景才能转换阴影。如果没有关于您的 @drawable/button_flat_white 的信息,我无法判断这是否是您的问题。

要解决您的问题,您应该像这样修改 FrameLayout:

<FrameLayout
        android:id="@+id/fragment_container_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"

        android:clipToPadding="false"
        android:paddingBottom="10dp"/>

要检查您的 @drawable/button_flat_white 是否会导致任何问题,请尝试将 LinearLayout 的背景临时更改为简单的颜色:

<LinearLayout
    android:id="@+id/panelAddress"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="10dp"
    android:orientation="vertical"
    android:padding="20dp"

    android:background="#fff">  
//some content
</LinearLayout>

关于android - 高程不适用于 LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33417049/

相关文章:

android - 在 fragment 中使用 Material 对话框

android - Firebase 两种数据库(iOS、Android)

java - 将 Activity 元素的排列设置为从左到右(默认)

android - 获取 View 的当前背景id

android - 如何以编程方式设置 TextView 的边框颜色?

angular - Material Design 2 选项卡底部对齐

android - 如何获得两个gps地址之间的差异

android - 使用 picasso 加载图像时淡入动画

android - 如何访问 fragment 中的 UI 元素?

Android TimePickerDialog Material 设计颜色