[英]How to make 2 images views each be sized to cover screen inside a linear layout inside a horizontal scrollview
I'm trying to get 2 (or more as needed) imageviews inside a linearlayout inside a horizontalscrollview, such that each image is scaled to fit the screen height without distorting the image ie one image showing as large as possible on screen, scroll to see next one. 我试图在horizontalscrollview内的linearlayout内获得2(或更多根据需要)的图像视图,这样每个图像都可以缩放以适应屏幕高度而不会扭曲图像,即一个图像在屏幕上显示尽可能大,滚动查看下一个。
once the second image is added, i get 2 small images next to each other (dimensions are 217 * 300px for both images). 一旦添加了第二个图像,我就会得到彼此相邻的2个小图像(两个图像的尺寸都是217 * 300px)。 currently my activity_main.xml looks like the following..
目前我的activity_main.xml如下所示..
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/image1"
android:src="@drawable/luke"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
/>
<ImageView
android:id="@+id/image2"
android:src="@drawable/luke"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
/>
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
I've tried various combinations of match_parent, fill_parent, wrap_content on the layouts, all the scaleTypes on the image views and spent over a day browsing the net looking for an example similar to what i want, but no luck. 我已经尝试了布局上的match_parent,fill_parent,wrap_content的各种组合,图像视图上的所有scaleTypes,并花了一天时间浏览网络寻找类似于我想要的示例,但没有运气。
I would say to set these two things: 我会说这两件事:
<ImageView
android:layout_height = "match_parent"
android:layout_width = "10dp" />
This is the tricky part. 这是棘手的部分。 Get the screen width at runtime, and set it to the imageView.
在运行时获取屏幕宽度,并将其设置为imageView。
I'd be inclined to use a viewpager with a custom page adapter showing your scaled imageview instead of trying to do it in way you are currently. 我倾向于使用带有自定义页面适配器的viewpager来显示您的缩放imageview,而不是尝试以您当前的方式执行此操作。
The view pager / adapter would handle view recyling, page snapping etc for you. 视图寻呼机/适配器将为您处理视图重新打印,页面捕捉等。
how about using 如何使用
android:width="0"
android:weight ="1"
android:height="match_parent"
In the imageViews 在imageViews中
and match_parent else where in your layout. 和match_parent否则布局中的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.