在android studio中显示url中的可滚动图像
我试图创建一个活动,显示从url获取的图像。我希望图像的宽度适应屏幕,但是图像的高度可以比屏幕长,这样图像就可以滚动(垂直)。 首先,我显示了一个可绘制文件夹中的图像,它使用了以下代码:在android studio中显示url中的可滚动图像,android,url,scroll,imageview,ion,Android,Url,Scroll,Imageview,Ion,我试图创建一个活动,显示从url获取的图像。我希望图像的宽度适应屏幕,但是图像的高度可以比屏幕长,这样图像就可以滚动(垂直)。 首先,我显示了一个可绘制文件夹中的图像,它使用了以下代码: <ScrollView android:layout_width="fill_parent" android:id="@+id/scrollView1" android:layout_height="wrap_content" android:layout_alignPar
<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>
图像已加载,但不再可滚动,并且不会按需要显示。
你有什么解决办法吗?
谢谢我通过在ScrollView、ImageView和LinearLayout中设置android:layout\u width=“match\u 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>
您想向哪个方向滚动?我想向垂直方向滚动。一种方法是创建自定义imageView并启用垂直滚动,另一种方法是将imageView置于垂直滚动视图中,这不是我将imageView置于滚动视图中所做的吗?如果将imageView置于滚动视图中会遇到什么问题
<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>