微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决具有旋转属性的视图被截断

  • 我必须创建三个类似 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 而不是约束来像图像中那样堆叠视图。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。