如何使用 Cardview 进行此设计
How to make this design with Cardview
我正在尝试在 xml 中进行此设计,但我不确定它是否可能是我想要的。
我想在右侧有一个框和三个图标(为每个卡片视图生成),分为两个布局,但都在同一个卡片视图中。
是否可以,或者我是否必须使用 cardview 作为第一个框并单独放置按钮?
希望以下代码对您有所帮助,
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="1dp"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent=".8"/>
<ImageView
android:id="@+id/image"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/actionLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintLeft_toRightOf="@+id/guideline"
app:layout_constraintRight_toRightOf="parent" >
<Button
android:id="@+id/likeButton"
style="?attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="100" />
<Button
android:id="@+id/disLikeButton"
style="?attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="100" />
<Button
android:id="@+id/optionButton"
style="?attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:iconGravity="end" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
我正在尝试在 xml 中进行此设计,但我不确定它是否可能是我想要的。
我想在右侧有一个框和三个图标(为每个卡片视图生成),分为两个布局,但都在同一个卡片视图中。 是否可以,或者我是否必须使用 cardview 作为第一个框并单独放置按钮?
希望以下代码对您有所帮助,
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="1dp"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent=".8"/>
<ImageView
android:id="@+id/image"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/actionLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintLeft_toRightOf="@+id/guideline"
app:layout_constraintRight_toRightOf="parent" >
<Button
android:id="@+id/likeButton"
style="?attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="100" />
<Button
android:id="@+id/disLikeButton"
style="?attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="100" />
<Button
android:id="@+id/optionButton"
style="?attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:iconGravity="end" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>