高程在LinearLayout中不起作用

时间:2018-07-26 10:13:27

标签: android

bg_book_promotion是需要有阴影的图片 当我添加android:elevation时,它不起作用。 谁能告诉我如何纠正它,真是太奇怪了。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/color_fff_white"
    android:orientation="vertical">

    <LinearLayout
            android:id="@+id/ll_promotion_bg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/margin9"
            android:layout_marginLeft="@dimen/margin7"
            android:layout_marginRight="@dimen/margin7"
            android:layout_marginTop="@dimen/margin14"
            android:background="@drawable/bg_book_promotion"
            android:elevation="@dimen/height2"
            android:gravity="center_vertical"
            android:orientation="vertical"
            android:paddingLeft="@dimen/padding9">

            <TextView
                android:id="@+id/tv_promotion_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/color_fff_white"
                android:textSize="@dimen/textsize15"
                android:textStyle="bold"
                tools:text="" />

            <TextView
                android:id="@+id/tv_promotion_desc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:textColor="@color/color_fff_white"
                android:textSize="@dimen/textsize12"
                tools:text="" />
        </LinearLayout>
 </LinearLayout>

enter image description here

2 个答案:

答案 0 :(得分:0)

只需添加android:outlineProvider =“ bounds”

<LinearLayout
    android:id="@+id/ll_promotion_bg"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/margin9"
    android:layout_marginLeft="@dimen/margin7"
    android:layout_marginRight="@dimen/margin7"
    android:layout_marginTop="@dimen/margin14"
    android:background="@drawable/bg_book_promotion"
    android:elevation="@dimen/height2"
    android:outlineProvider="bounds"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:paddingLeft="@dimen/padding9">

答案 1 :(得分:0)

仅使用CardView作为线性布局的父级,您将获得高程。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/color_fff_white"
    android:orientation="vertical">

<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    card_view:cardUseCompatPadding="true"
    card_view:cardElevation="8dp"
    card_view:cardCornerRadius="3dp">

<LinearLayout
            android:id="@+id/ll_promotion_bg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/margin9"
            android:layout_marginLeft="@dimen/margin7"
            android:layout_marginRight="@dimen/margin7"
            android:layout_marginTop="@dimen/margin14"
            android:background="@drawable/bg_book_promotion"
            android:elevation="@dimen/height2"
            android:gravity="center_vertical"
            android:orientation="vertical"
            android:paddingLeft="@dimen/padding9">

            <TextView
                android:id="@+id/tv_promotion_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/color_fff_white"
                android:textSize="@dimen/textsize15"
                android:textStyle="bold"
                tools:text="" />

            <TextView
                android:id="@+id/tv_promotion_desc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:textColor="@color/color_fff_white"
                android:textSize="@dimen/textsize12"
                tools:text="" />
        </LinearLayout>

</android.support.v7.widget.CardView>
</LinearLayout>