繁体   English   中英

在视图底部添加阴影

[英]Add shadow to bottom of view

我在这个布局上遇到了很多麻烦。

基本上我有 2 条线状线,一条线略带灰色,底部有阴影,另一条线线下方只有白色。 我的麻烦是将阴影添加到第一个线性的末尾。 我尝试了“海拔”,但这就是我现在需要的,因为如果最后 10dp 来自不同的颜色,我希望阴影在线性范围内,但我没有做对。

在此处输入图片说明

到目前为止,这是我的布局,我想在第一个线性内部放置一个视图,但效果不佳。

任何想法如何做到这一点?

<?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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:background="#f8f8f8"
        android:layout_height="0dp">

        <android.support.v7.widget.CardView
            app:cardCornerRadius="10dp"
            app:cardElevation="10dp"
            android:layout_width="312dp"
            android:layout_height="204dp"
            app:cardBackgroundColor="@android:color/holo_red_light"/> 
    </LinearLayout>


    <LinearLayout
        android:background="#ffffff"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="0dp">

    </LinearLayout>
</LinearLayout>

尝试在使用以下行linearlayout下,你的cardview坐着。

android:elevation="8dp"

cardElevation中的cardElevation部分保持cardView

card_view:cardElevation="10dp"
card_view:cardPreventCornerOverlap="false"

也只是一个建议:

如果您在两个子linearLayout使用android:layout_weightandroid:weightSum="2"放在您的父linearLayout如@Ming Leung here给出的答案中所述

有关android:weightSum="2"更多信息,您可以参考此页面上的答案

页面将帮助你elevationcardview

希望有帮助。

我能够使用 ConstraintLayout 让它工作:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.cardview.widget.CardView
        android:layout_width="312dp"
        android:layout_height="204dp"
        app:cardBackgroundColor="@android:color/holo_red_light"
        app:cardCornerRadius="10dp"
        app:cardElevation="10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" >

    </androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM