具有旋转属性的视图被截断

问题描述

  • 我必须创建三个类似 CardView 的结构,如下图所示。为此,我目前正在使用 Constraintlayout 但面临多个问题,即剪辑问题。
  • 没有滑动动画之类的用例。
  • 有什么我遗漏的地方吗。任何帮助将不胜感激。

enter image description here

这是我的代码

<androidx.constraintlayout.widget.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <androidx.cardview.widget.CardView
                            android:id="@+id/card_one"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:rotation="-20"
                            android:layout_marginTop="@dimen/dimen_12"
                            android:layout_marginStart="@dimen/dimen_25"
                            app:cardCornerRadius="@dimen/dimen_8"
                            app:cardElevation="@dimen/dimen_1"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent">

                            <RelativeLayout
                                android:id="@+id/rl_one"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:background="@drawable/top_colored_gradient_dark"
                                android:padding="@dimen/dimen_12">

                                <de.hdodenhof.circleimageview.CircleImageView
                                    android:id="@+id/img_one"
                                    android:layout_width="72dp"
                                    android:layout_height="72dp"
                                    android:src="@drawable/blue_social" />

                                <TextView
                                    android:id="@+id/txt_name"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@id/img_one"
                                    android:layout_centerHorizontal="true"
                                    android:layout_marginTop="@dimen/dimen_15"
                                    android:textColor="#313131"
                                    android:textSize="@dimen/dimen_14sp"
                                    tools:text="Title Here" />

                                <TextView
                                    android:id="@+id/txt_date"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@id/txt_name"
                                    android:layout_centerHorizontal="true"
                                    android:textColor="@color/light_text_color"
                                    android:textSize="@dimen/dimen_11sp"
                                    tools:text="Date" />
                            </RelativeLayout>
                        </androidx.cardview.widget.CardView>

                        <androidx.cardview.widget.CardView
                            android:id="@+id/card_second"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            app:cardElevation="@dimen/dimen_2"
                            app:cardUseCompatPadding="true"
                            app:cardCornerRadius="@dimen/dimen_8"
                            android:layout_marginEnd="@dimen/dimen_15"
                            app:layout_constraintEnd_toStartOf="@id/card_third"
                            app:layout_constraintStart_toEndOf="@id/card_one"
                            app:layout_constraintTop_toTopOf="parent">

                            <RelativeLayout
                                android:id="@+id/rl_two"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:background="@drawable/top_colored_gradient_dark"
                                android:padding="@dimen/dimen_12">

                                <de.hdodenhof.circleimageview.CircleImageView
                                    android:id="@+id/img_two"
                                    android:layout_width="72dp"
                                    android:layout_height="72dp"
                                    android:src="@drawable/blue_social" />

                                <TextView
                                    android:id="@+id/txt_name_two"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@id/img_two"
                                    android:layout_centerHorizontal="true"
                                    android:layout_marginTop="@dimen/dimen_15"
                                    android:textColor="#313131"
                                    android:textSize="@dimen/dimen_14sp"
                                    tools:text="Title Here" />

                                <TextView
                                    android:id="@+id/txt_date_two"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@id/txt_name_two"
                                    android:layout_centerHorizontal="true"
                                    android:textColor="@color/light_text_color"
                                    android:textSize="@dimen/dimen_11sp"
                                    tools:text="Date" />
                            </RelativeLayout>
                        </androidx.cardview.widget.CardView>

                        <androidx.cardview.widget.CardView
                            android:id="@+id/card_third"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            app:cardElevation="@dimen/dimen_1"
                            app:cardCornerRadius="@dimen/dimen_8"
                            android:layout_marginTop="@dimen/dimen_8"
                            android:rotation="20"
                            app:cardUseCompatPadding="true"
                            app:layout_constraintStart_toEndOf="@id/card_second"
                            app:layout_constraintTop_toTopOf="parent">

                            <RelativeLayout
                                android:id="@+id/rl_third"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:background="@drawable/top_colored_gradient_dark"
                                android:padding="@dimen/dimen_12">

                                <de.hdodenhof.circleimageview.CircleImageView
                                    android:id="@+id/img_third"
                                    android:layout_width="72dp"
                                    android:layout_height="72dp"
                                    android:src="@drawable/blue_social" />

                                <TextView
                                    android:id="@+id/txt_name_third"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@id/img_third"
                                    android:layout_centerHorizontal="true"
                                    android:layout_marginTop="@dimen/dimen_15"
                                    android:textColor="#313131"
                                    android:textSize="@dimen/dimen_14sp"
                                    tools:text="Title Here" />

                                <TextView
                                    android:id="@+id/txt_date_third"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@id/txt_name_third"
                                    android:layout_centerHorizontal="true"
                                    android:textColor="@color/light_text_color"
                                    android:textSize="@dimen/dimen_11sp"
                                    tools:text="Date" />
                            </RelativeLayout>
                        </androidx.cardview.widget.CardView>

                    </androidx.constraintlayout.widget.ConstraintLayout>

解决方法

您可以使用 FrameLayout 而不是约束来像图像中那样堆叠视图。

相关问答

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