[英]How to make Image Views centre in a linear layout inside a Horizontal Scroll View?
[英]How to make 2 images views each be sized to cover screen inside a linear layout inside a horizontal scrollview
我试图在horizontalscrollview内的linearlayout内获得2(或更多根据需要)的图像视图,这样每个图像都可以缩放以适应屏幕高度而不会扭曲图像,即一个图像在屏幕上显示尽可能大,滚动查看下一个。
一旦添加了第二个图像,我就会得到彼此相邻的2个小图像(两个图像的尺寸都是217 * 300px)。 目前我的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>
我已经尝试了布局上的match_parent,fill_parent,wrap_content的各种组合,图像视图上的所有scaleTypes,并花了一天时间浏览网络寻找类似于我想要的示例,但没有运气。
我会说这两件事:
<ImageView
android:layout_height = "match_parent"
android:layout_width = "10dp" />
这是棘手的部分。 在运行时获取屏幕宽度,并将其设置为imageView。
我倾向于使用带有自定义页面适配器的viewpager来显示您的缩放imageview,而不是尝试以您当前的方式执行此操作。
视图寻呼机/适配器将为您处理视图重新打印,页面捕捉等。
如何使用
android:width="0"
android:weight ="1"
android:height="match_parent"
在imageViews中
和match_parent否则布局中的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.