卡片视图周围的边框
border around a cardview
我想在我的卡片视图周围放一个蓝色边框,但我无法放上去。它适用于 Constraint Layout 标签,但不适用于 CardView
card_edge.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dip" android:color="#3683D6" />
<corners android:radius="5dp" />
</shape>
item_game_list.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true">
<androidx.cardview.widget.CardView
android:background="@drawable/card_edge"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
.
.
.
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
在 cardview 的子布局中使用你的可绘制文件,即 @drawable/card_edge(在我的例子中是 LinearLayout,但你可以根据你的要求使用任何布局。),它将创建 UI你的要求。
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:focusable="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
android:padding="5dp"
android:elevation="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/card_edge"
>
.
.
.
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
我想在我的卡片视图周围放一个蓝色边框,但我无法放上去。它适用于 Constraint Layout 标签,但不适用于 CardView
card_edge.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dip" android:color="#3683D6" />
<corners android:radius="5dp" />
</shape>
item_game_list.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true">
<androidx.cardview.widget.CardView
android:background="@drawable/card_edge"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
.
.
.
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
在 cardview 的子布局中使用你的可绘制文件,即 @drawable/card_edge(在我的例子中是 LinearLayout,但你可以根据你的要求使用任何布局。),它将创建 UI你的要求。
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:focusable="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
android:padding="5dp"
android:elevation="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/card_edge"
>
.
.
.
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>