如何使ImageView的拖动从左至右

问题描述:

我使用覆盖设备的整个画面像下面的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" 

>

<HorizontalScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:scrollbars="horizontal"> 

<ImageView 
    android:id="@+id/image" 
    android:layout_width="1000dp" 
    android:layout_height="match_parent" 
    android:scaleType="centerCrop" 
    /> 

</HorizontalScrollView> 

<RelativeLayout 
    android:id="@+id/rl_header" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/gradient_top" 
    android:padding="15dp" 
    > 

    <ImageView 
     android:id="@+id/iv_back" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/back_arrow" 
     android:padding="10dp" 
     android:visibility="visible" 
     android:layout_alignParentLeft="true"/> 


    <TextView 
     android:id="@+id/tv_header_wallpaper_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Cityscape in a dark, cold abyss of light and fire" 
     android:textColor="@color/white_color" 
     android:textSize="19sp" 
     android:layout_toRightOf="@+id/iv_back" 
     android:gravity="center" 
     android:paddingTop="5dp" 
     android:paddingRight="40dp" 
     /> 

</RelativeLayout> 

<ProgressBar 
    android:id="@+id/loading" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:indeterminateTint="@color/white_color" 
    android:visibility="visible" /> 


<RelativeLayout 
    android:id="@+id/rl_bottom" 
    android:layout_width="match_parent" 
    android:layout_height="75dp" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="0dp" 
    android:background="@drawable/gradient_bottom"> 

    <ImageView 
     android:id="@+id/iv_set_wallpaper" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/download_icon" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="20dp" 
     android:layout_centerVertical="true"/> 


    <ImageView 
     android:id="@+id/iv_favourite" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/favorites" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="20dp"/> 

</RelativeLayout> 

现在我已经从图像url下载了约20 Mb大小的图像,并在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> 
+0

没有工作:(无法滚动IMAGEVIEW) –

+0

我测试了它,它对我很好,你的问题必须在别处。其他答案给你相同或类似的解决方案... –

+0

这是我的应用您的解决方案的XML文件。请让我知道我错在哪里? –

<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> 

这将帮助你。 请投票,如果这有帮助:)