高度在LinearLayout上不起作用 [英] Elevation not working on a LinearLayout

查看:81
本文介绍了高度在LinearLayout上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在寻找解决方案后,我没有找到解决问题的方法.

After searching for a solution, I didn't find any to solve my problem.

我有一些仰角,这会在我的应用程序的很大一部分上产生阴影.
但是在特定的地方,我无法使其正常工作.
(这是我在下面的图片上放一个箭头的地方)

I have some elevation which produces a shadow on a big part of my app.
But in a particular place, I'm not able to make it work.
(It's where I put an arrow on the picture below)

工具栏下方的白色区域是Fragment,其中显示LinearLayout

The white area below the toolbar is a Fragment which displays a 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>

片段的父对象:

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

您对我为什么不得到海拔高度有想法吗?

Do you have an idea about why I don't get my elevation?

推荐答案

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

As described here https://stackoverflow.com/a/27518160/2481494 there are several requirements so that the shadow is drawn:

  • 空格用于父视图组中的阴影.如出血182所述,填充会导致阴影被修剪:

  • Space for the shadow in the parents view Group. As bleeding182 mentioned, padding can cause the shadow to be clipped:

(请勿使用填充.框架布局上的填充也将遮挡阴影)

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

但是,可以使用父级中的android:clipToPadding="false"修复此问题.

However, this can be fixed with android:clipToPadding="false" in the parent.

高架视图需要具有背景才能投射阴影.没有有关您的@drawable/button_flat_white的信息,我无法确定这是否是您的问题.

The elevated view needs to have a background to cast a shadow. Without information about your @drawable/button_flat_white I can't tell whether this is a problem in your case.

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

To solve your problem you should modify your FrameLayout like this:

<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的背景临时更改为简单的颜色:

To check whether your @drawable/button_flat_white causes any problems try to change the background of your LinearLayout to a simple color temporarily:

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

这篇关于高度在LinearLayout上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆