如何在relativelayout中找到Imageview的位置或坐标?

时间:2018-01-27 10:57:01

标签: android

这是我的页面布局。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/fullMeetingView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="top"
        android:layout_weight=".1"
        android:background="@color/colorPaleGrey2"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginTop="20dp">

            <TextView
                android:id="@+id/meeting_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-medium"
                android:gravity="center_horizontal"
                android:text="Entrepreneur Meet Up"
                android:textColor="@color/blackDark"

                android:textSize="20.1sp"
                android:textStyle="normal" />

            <TextView
                android:id="@+id/time"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/meeting_text"
                android:layout_centerInParent="true"
                android:layout_marginTop="10dip"
                android:fontFamily="sans-serif-medium"
                android:gravity="center_horizontal"
                android:lineSpacingExtra="6sp"
                android:text="(11:30AM - 4:00PM)"
                android:textColor="@color/bluey_grey_three"
                android:textSize="14sp"
                android:textStyle="normal" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/rlmainLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.kdcos.contsync.utilities.dragview.DragLayer
                android:id="@+id/framelayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">


            </com.kdcos.contsync.utilities.dragview.DragLayer>
            <RelativeLayout
                android:id="@+id/rl_dropView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@drawable/round_bg"
                android:padding="30dp">

                <ImageView
                    android:id="@+id/imageView"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:background="@drawable/ic_drop_cards" />

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/imageView"
                    android:layout_centerInParent="true"
                    android:layout_gravity="center_horizontal|center"
                    android:fontFamily="sans-serif"
                    android:gravity="center_horizontal"
                    android:lineSpacingExtra="10sp"
                    android:text="Drop Cards Here"
                    android:textColor="@color/blackDark"
                    android:textSize="10sp"
                    android:textStyle="normal" />
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/delete_zone_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:gravity="bottom"
                android:orientation="horizontal"
                android:visibility="visible">

                <ImageView
                    android:id="@+id/deleteButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"                        android:padding="@dimen/margin_20dp"
                    android:background="@drawable/ic_delete" />
            </RelativeLayout>


        </RelativeLayout>



    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:layout_weight=".2">

        <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/drawer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:openDrawer="start">

            <android.support.design.widget.CoordinatorLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                tools:context="com.guna.navigationviewonbothssides.MainActivity">

                <android.support.design.widget.AppBarLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    app:elevation="0dp">


                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">


                        <android.support.design.widget.TabLayout
                            android:id="@+id/tabLayout"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_toLeftOf="@+id/menuRight"
                            android:background="@color/colorWhite"
                            android:minHeight="?attr/actionBarSize"
                            app:tabGravity="fill"
                            app:tabIndicatorColor="@color/colorTurquoiseBlue"
                            app:tabIndicatorHeight="3dp" />

                        <RelativeLayout
                            android:id="@+id/menuRight"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:background="@color/blackDark"
                            android:padding="10dp"
                            android:tint="@color/colorPrimary">

                            <ImageButton
                                android:layout_width="16dp"
                                android:layout_height="16dp"
                                app:srcCompat="@drawable/ic_menu_white_24dp"

                                />

                        </RelativeLayout>


                    </RelativeLayout>

                </android.support.design.widget.AppBarLayout>

                <android.support.v4.view.ViewPager
                    android:id="@+id/viewpager_meeting_landscape"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginTop="50dp"
                    android:background="@color/colorWhite" />

            </android.support.design.widget.CoordinatorLayout>


            <android.support.design.widget.NavigationView
                android:id="@+id/nav_view"
                android:layout_width="200dp"
                android:layout_height="match_parent"
                android:layout_gravity="end"

                android:fitsSystemWindows="true">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerview_drawer_list"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingTop="10dp"
                    android:visibility="visible"
                    android:scrollbars="vertical" />


                <TextView
                    android:id="@+id/empty_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingTop="10dp"
                    android:scrollbars="vertical"
                    android:gravity="center"
                    android:text="@string/no_meeting_fount"
                    android:visibility="gone" />
            </android.support.design.widget.NavigationView>
        </android.support.v4.widget.DrawerLayout>
    </LinearLayout>
</LinearLayout>

enter image description here

我想获取弹出位置坐标,这样我可以在删除listview项目时执行某些操作

我尝试使用getLocationInWindow()x和y坐标,但我总是得到x轴-0而不是0位置我必须得到弹出位置或删除按钮区域,以便我可以触摸列表视图项目视图删除位置请建议我如何找到删除图像视图坐标或位置。

1 个答案:

答案 0 :(得分:0)

我认为原因是当您尝试获取其坐标时屏幕上还没有绘制视图,这就是为什么它总是为x或y坐标返回0的原因

请参阅以下链接以了解类似问题并从中获取解决方案 请参阅以下链接 Getting 0 Value for both X and Y Coordinate of view(Imagebutton) in android