锚定视图以显示在单击的位置?

问题描述 投票:-1回答:1

我有一个包含许多图像的RecyclerView。当长时间点击图像时,我取消隐藏RelativeView(通过setVisibility(View.VISIBLE))以在ImageView中显示图像的“预览”,直到长按发布,此时我再次隐藏预览。目前,除了预览总是显示在屏幕上的相同位置之外,这是按预期工作的。

有没有办法将预览锚定到用户点击的位置?理想情况下,我希望底角与用户长按(或至少底边)的位置对齐。这是我目前预览的样子:

enter image description here

这是RecyclerView和预览容器布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Recyclerview -->
    <com.sometimestwo.moxie.MultiClickRecyclerView
        android:id="@+id/recycler_zoomie_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- Preview container that gets hidden/unhidden-->
    <RelativeLayout
        android:id="@+id/hover_view_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center|top"
        android:visibility="gone">

        <TextView
            android:id="@+id/hover_view_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorBgBlackTint"
            android:gravity="center"
            android:textColor="@color/colorWhite"
            android:visibility="visible" />

        <ImageView
            android:id="@+id/hover_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/hover_view_title"
            android:background="@color/colorBgBlackTint"
            android:visibility="visible" />
    </RelativeLayout>

</FrameLayout>
android android-layout android-imageview android-relativelayout
1个回答
1
投票

您可以使用PopupWindow。您可以将特定视图设置为锚点以显示窗口,在窗口内可以显示预览。

© www.soinside.com 2019 - 2024. All rights reserved.