如何使用Cardview进行此设计

问题描述

我正在尝试使用xml进行这种设计,但是我不确定是否可能得到我想要的东西。

enter image description here

我想在右侧有一个框和三个图标(为每个Cardview生成),以两个布局分开,但全部在同一Cardview中。 是否有可能还是我必须将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>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...