Android 如何使ImageView从左向右拖动

Android 如何使ImageView从左向右拖动,android,imageview,Android,Imageview,我使用的ImageView覆盖了设备的全屏,如下所示:- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#1A1A1A" 现在我已经

我使用的ImageView覆盖了设备的全屏,如下所示:-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1A1A1A"


现在我已经从图像url下载了大小约为20MB的图像,并在imageview中设置了图像。问题是图像的宽度比设备的宽度大。当我在图像视图中应用或设置相同的图像时,它会压缩大小并设置为全屏视图。我想要的是,这个形象不应该被挤压。图像视图只能从左侧和右侧拖动。高度应根据设备固定


如何使图像视图可拖动?

此布局允许滚动图像:

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

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

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:src="@drawable/bigimage" />
    </HorizontalScrollView>

</ScrollView>



这会有帮助。

我测试了它,它对我很好,你的问题肯定在别处。其他答案给出了相同或类似的解决方案……这是我的XML文件,我在其中应用了您的解决方案。请让我知道我错在哪里?您的布局完全错误,只有一个根元素(例如相对布局)必须包含其中的所有元素。如果添加更多视图或嵌套布局,则所有视图或嵌套布局都必须位于唯一的根元素内。我建议您首先使用基本布局来了解其工作原理
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

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

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:src="@drawable/bigimage" />
    </HorizontalScrollView>

</ScrollView>
<HorizontalScrollView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">
    <ScrollView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content">
        <ImageView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />
    </ScrollView>
</HorizontalScrollView>