简体   繁体   English

在android studio中显示来自网址的可滚动图像

[英]Display a scrollable image from a url in android studio

I'm trying to create an activity that display an image that is obtained from an url. 我正在尝试创建一个活动,该活动显示从URL获得的图像。 I want the width of the image to adapt the screen but the height of the image can be longer than the screen so that the image becomes scrollable (vertically). 我希望图像的宽度适应屏幕,但是图像的高度可以比屏幕长,以便图像可以滚动(垂直)。 First of all, I displayed the image from a drawable folder and it worked with the following code : 首先,我显示了可绘制文件夹中的图像,并使用以下代码工作:

<ScrollView
    android:layout_width="fill_parent"
    android:id="@+id/scrollView1"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:scrollbarAlwaysDrawVerticalTrack="true">
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal">



        <ImageView

            android:src="@drawable/programme"
            android:layout_height="wrap_content"
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:scaleType="fitStart"></ImageView>
    </LinearLayout>
</ScrollView>

I obtained what I wanted : http://i.stack.imgur.com/imPkZ.png 我获得了想要的东西: http : //i.stack.imgur.com/imPkZ.png

But now I wanted the image to charge from an URL so I used the ion library : 但是现在我希望图像从URL收费,所以我使用了离子库:

Ion.with(imageView)

            .load("http://...");

The image load but it is no longer scrollable and doesn't display as wanted. 图像已加载,但不再可滚动并且无法按需要显示。 http://i.gyazo.com/704324724364235bbe417d5447265c42.png http://i.gyazo.com/704324724364235bbe417d5447265c42.png

Do you have any solution? 你有什么解决办法吗? Thanks 谢谢

I found the solution by setting android:layout_width="match_parent" in ScrollView, ImageView and LinearLayout and setting android:adjustViewBounds="true" for ImageView like this : 我通过在ScrollView,ImageView和LinearLayout中设置android:layout_width =“ match_parent”并为ImageView设置android:adjustViewBounds =“ true”来找到解决方案,如下所示:

<ScrollView
    android:layout_width="match_parent"
    android:id="@+id/scrollView1"
    android:layout_height="wrap_content"
    android:scrollbarAlwaysDrawVerticalTrack="true">
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitStart"
            android:adjustViewBounds="true"/>
    </LinearLayout>
</ScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM