我在这个布局上遇到了很多麻烦。
基本上,我有两个线,一个是轻微灰色的阴影在底部和下方,另一个线性,只是白色。我的问题是在第一个直线的末尾加上那个阴影。我试过“高度”,但这是我现在需要的,因为我希望阴影在线性,如果最后的10‘m是来自不同的颜色,但我没有得到正确的。

到目前为止,这是我的布局,我想在第一个直线中放一个视图,但它不太好用。
有什么办法吗?
<?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>发布于 2020-01-02 23:33:59
试着在linearlayout中使用下面的行,您的cardview就在下面。
android:elevation="8dp"
让您的cardView中的cardView部件保持原样。
card_view:cardElevation="10dp"
card_view:cardPreventCornerOverlap="false"还有一个建议:
如果您在两个孩子中都使用android:layout_weight,linearLayout将android:weightSum="2"放在父母linearLayout中,如@明梁here的回答中提到的那样。
有关android:weightSum="2"的更多信息,请参阅此page的答案
这个page将帮助您在elevation in cardview
希望这能有所帮助。
发布于 2020-01-02 23:25:40
我能够让它使用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>

https://stackoverflow.com/questions/59571072
复制相似问题