如何在android中防止imageview重叠

如何在android中防止imageview重叠,android,xml,imageview,android-relativelayout,Android,Xml,Imageview,Android Relativelayout,我想把多个imageview像这样排成一行 但是有一些bug,imageview相互重叠,我想把它们并排放置 下面是我的XML文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:lay

我想把多个imageview像这样排成一行

但是有一些bug,imageview相互重叠,我想把它们并排放置

下面是我的XML文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@drawable/background"
    android:clipChildren="false"
    android:clipToPadding="false"
    tools:context=".MainActivity" > 

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="182dp"
        android:layout_marginEnd="10dp"
        android:layout_marginRight="10dp"
        android:scaleType="centerCrop"
        android:src="@drawable/music_720p" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/imageView1"
        android:layout_toEndOf="@+id/imageView1"
        android:layout_marginTop="182dp"
        android:layout_marginRight="70dp"
        android:layout_marginEnd="70dp"
        android:scaleType="centerCrop"
        android:src="@drawable/video_720p" />
    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/imageView2"
        android:layout_toEndOf="@+id/imageView2"
        android:layout_marginTop="182dp"
        android:layout_marginRight="70dp"
        android:layout_marginEnd="70dp"
        android:scaleType="centerCrop"
        android:src="@drawable/photo_720p" />
    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/imageView3"
        android:layout_toEndOf="@+id/imageView3"
        android:layout_marginTop="182dp"
        android:layout_marginRight="10dp"
        android:layout_marginEnd="10dp"
        android:scaleType="centerCrop"
        android:src="@drawable/web_720p" />
    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/imageView4"
        android:layout_toEndOf="@+id/imageView4"
        android:layout_marginTop="182dp"
        android:layout_marginRight="10dp"
        android:layout_marginEnd="10dp"
        android:scaleType="centerCrop"
        android:src="@drawable/setting_720p" /> 

</RelativeLayout>

非常感谢您的帮助。

我建议您选择HorizontalScrollView,它提供您想要的功能

Checkout链接向您展示了如何实现

我希望这对你有帮助

您还可以检查vijju的答案,他们已经完全展示了实现


请试试这个。我希望能对您有所帮助。

我可以看到您在任何地方都使用了wrap\u内容,因此您可以减少图像的宽度和高度,也可以在布局文件或.java文件中明确定义它

对于您的场景,使用GridLayout比使用RelativeLayout更好。试试看。。。
下面是一个关于GridLayout的好例子:-

使用GridView或HorzontalScrollView。并正确使用RelativeLayout属性。你知道android中的GridView和HorizontalScrollView吗?我改为GridLayout,它工作得很好,谢谢!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:clipChildren="false"
    android:clipToPadding="false"
    tools:context=".MainActivity" > 

  <HorizontalScrollView
      android:id="@+id/horizontalScrollView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="false"
      android:scrollbars="none" >

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <ImageView
                        android:id="@+id/setupImageView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|left"
                        android:layout_marginBottom="10dp"
                        android:layout_marginLeft="20dp"
                        android:src="@drawable/ic_launcher" />

                    <ImageView
                        android:id="@+id/uploadImageView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|center"
                        android:layout_marginBottom="10dp"
                        android:layout_marginLeft="30dp"
                        android:src="@drawable/ic_launcher" />

                    <ImageView
                        android:id="@+id/visulizationImageView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|right"
                        android:layout_marginBottom="10dp"
                        android:layout_marginLeft="30dp"
                        android:src="@drawable/ic_launcher" />

                    <ImageView
                        android:id="@+id/setupImageView2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|left"
                        android:layout_marginBottom="10dp"
                        android:layout_marginLeft="20dp"
                        android:src="@drawable/ic_launcher" />

                    <ImageView
                        android:id="@+id/uploadImageView2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|center"
                        android:layout_marginBottom="10dp"
                        android:layout_marginLeft="30dp"
                        android:src="@drawable/ic_launcher" />

                    <ImageView
                        android:id="@+id/visulizationImageView2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|right"
                        android:layout_marginBottom="10dp"
                        android:layout_marginLeft="30dp"
                        android:src="@drawable/ic_launcher" />
                </LinearLayout>

            </HorizontalScrollView>

</RelativeLayout>