ImageView顶部的精确视图位置-android

ImageView顶部的精确视图位置-android,android,Android,我试图通过在上面设置一些不可见的图像按钮来创建一个可交互的图像视图,然后用户可以单击图像的不同部分并对其进行处理,问题是我需要这些图像按钮相对于图像视图处于非常精确的位置,如果手机大小有一点变化,图像按钮将离开我想要的位置 图像视图所在的xml: <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width

我试图通过在上面设置一些不可见的图像按钮来创建一个可交互的图像视图,然后用户可以单击图像的不同部分并对其进行处理,问题是我需要这些图像按钮相对于图像视图处于非常精确的位置,如果手机大小有一点变化,图像按钮将离开我想要的位置

图像视图所在的xml:

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".fragments.Offroad18nitro4wdbuggy_frontFragment">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="OffRoad 1/8 nitro 4WD buggy front" /> <!-- Here just to show the programmer which fragment is showing -->

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_centerHorizontal="true">
    <ImageView
        android:id="@+id/ivLosi4_offroad18nitro4wdbuggy_front"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitCenter"
        android:src="@drawable/losi4_18scale_front"/>

    <ImageButton
        android:id="@+id/ibTest"
        android:layout_width="50dp"
        android:layout_height="41dp"
        android:alpha="0"
        android:background="@color/colorGreen"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="40dp"
        android:layout_marginTop="5dp"/>

</RelativeLayout>


我以前就处理过这个问题。我设法完成的解决方法是将屏幕分成几个子布局,使其看起来像一个布局网格。首先在中心点将屏幕一分为二,然后在顶部和底部布局的中心放置一个没有尺寸的空文本视图,这样可以将这些布局分成四个部分。然后对这四个做同样的事情,如果你必须的话,创造十六个。然后将图像按钮放置在这些布局中包含所需区域的任何布局的侧面或中心点上

重点是创建一个相对于屏幕中心固定的栅格。这样,如果屏幕大小发生变化,网格和与其相连的按钮将相应调整。这不是一个完美的解决方案,但它符合我的目的。下面是我在项目中使用此策略的示例xml文件的链接:


事实上,我花了几个小时调整了一下,现在它对每种屏幕大小都有效。非常感谢D