[英]Android: ImageView scale to screen width within a ScrollView
I'm quite new to android programming and I stumbled upon a problem with my layout
. 我是android编程的新手,偶然发现了一个
layout
问题。
At first, I had a Linearlayout
with a textview
, 2 buttons
and a imageview
scaled to fit the screen. 首先,我有一个
Linearlayout
,带有textview
,2个buttons
和一个可缩放以适合屏幕的imageview
。
Now I wanted to put this under a scrollview
, so the imageview
could be scaled larger (to the width of the screen). 现在,我想将其放置在
scrollview
,以便可以将imageview
缩放到更大的比例(缩放到屏幕的宽度)。
Without the scrollview
everything just went fine, but with the scrollview
, my imageview
is not scaled anymore. 没有
scrollview
一切都很好,但是有了scrollview
,我的imageview
不再缩放了。
What am I doing wrong ? 我做错了什么? I tried numerous solutions on StackOverflow but I can't get it to work with a
ScrollView
. 我在StackOverflow上尝试了许多解决方案,但无法使其与
ScrollView
一起使用。 Thanks in advance! 提前致谢!
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/pageno" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/texta" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/textb" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/page1" />
</LinearLayout>
</ScrollView>
Make LinearLayout/RelativeLayout as parent view. 使LinearLayout / RelativeLayout成为父视图。 In that make a scroll view and set alignparentTop=true.
在其中进行滚动视图并设置alignparentTop = true。 This scrollView will contain a single layout in which all other views will be placed.
该scrollView将包含一个布局,所有其他视图都将放置在该布局中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.