gpt4 book ai didi

java - 如何在卡片 View 的侧面设置颜色

转载 作者:太空宇宙 更新时间:2023-11-03 12:43:57 25 4
gpt4 key购买 nike

我试图了解像这样在 CardView 的一侧设置颜色的最佳方法是什么

enter image description here

我的卡片 View 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewWe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:foreground="?attr/selectableItemBackground"
android:transitionName="cardTransition"
app:cardBackgroundColor="@drawable/selector"
app:cardElevation="2dp"

card_view:cardCornerRadius="8dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
.....
.....
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

最佳答案

试试这个

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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="wrap_content"
android:orientation="vertical"
app:cardCornerRadius="10dp"
app:cardElevation="2dp"
app:cardUseCompatPadding="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="horizontal">

<View
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="@color/colorAccent" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="10dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nilesh Rathod" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nilesh Rathod" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nilesh Rathod" />

</LinearLayout>
</LinearLayout>


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

输出

enter image description here

关于java - 如何在卡片 View 的侧面设置颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53406388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com