我正在开发一个 Android 应用程序,我想在其中使用 RecyclerView 显示 GridView。
我可以为一个项目创建单独的布局并动态地将其显示在 GridView 中。但是我遇到了在每个项目的右上角显示刻度线的问题。
这是我的item_grid.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="110dp"
android:layout_height="110dp">
<android.support.v7.widget.CardView
android:id="@+id/cardView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:elevation="@dimen/activity_horizontal_margin">
<ImageView
android:id="@+id/image_hobby_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:src="@drawable/cycling" />
<TextView
android:id="@+id/text_hobby_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorAccent"
android:gravity="center"
android:padding="3dp"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:text="CYCLING"
android:textColor="@android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<ImageView
android:id="@+id/image_hobby_selected_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="top|right"
android:adjustViewBounds="true"
android:src="@drawable/all_checked_round" />
</FrameLayout>
我尝试过 bringToFront()
方法,但它不起作用。
viewHolder.checkMark.bringToFront();
((View) viewHolder.checkMark.getParent()).invalidate();
(viewHolder.checkMark.getParent()).requestLayout();
请帮我找到解决方案。
最佳答案
请使用海拔。
如果您的卡片 View 的标高为 10dp,则将 imageView 中的标高设置为 11dp。
<ImageView
android:id="@+id/image_hobby_selected_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="top|right"
android:adjustViewBounds="true"
android:src="@drawable/ic_camera"
android:elevation="13dp"
/>
关于android - 父 View 与 subview 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49706540/