简体   繁体   English

如何制作2个图像视图,每个视图的大小可以覆盖水平滚动视图内的线性布局内的屏幕

[英]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. 我试图在horizo​​ntalscrollview内的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.

相关问题 如何使图像视图在水平滚动视图内的线性布局中居中? - How to make Image Views centre in a linear layout inside a Horizontal Scroll View? 如何在ScrollView内强制线性布局到屏幕底部? - How to force a Linear layout to the bottom of the screen while it's inside a ScrollView? 以编程方式在(线性)布局内(即ScrollView内)添加Views - Programmatically add Views inside a (Linear)Layout (that is inside a ScrollView) 无法在Android的水平scrollview中滚动线性布局 - Unable to scroll linear layout inside a horizontal scrollview in android 查看在水平线性布局内的动态图像视图中走出屏幕 - View going out of screen in dynamic image views inside horizontal linear layout 滚动视图内部线性布局不滚动 - Scrollview inside linear layout not scrolling 滚动视图内的线性布局权重 - linear layout weight inside scrollview 如何使在滚动视图中(处于线性布局内)的视图无法创建? - How to keep views in scrollview (that are inside a linear layout) that are not visible from being created? 如何正确放置视图以使所有视图在“线性布局”中可见? - How to put views properly to make all views visible inside Linear Layout? 如何将可扩展列表视图和线性布局放入滚动视图 - How to put expandable listview and linear layout inside scrollview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM