3

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.

once the second image is added, i get 2 small images next to each other (dimensions are 217 * 300px for both images). currently my activity_main.xml looks like the following..

    <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.

4

3 回答 3

3

我会说设置这两件事:

     <ImageView
          android:layout_height = "match_parent"
          android:layout_width = "10dp" />

这是棘手的部分。在运行时获取屏幕宽度,并将其设置为 imageView。

于 2013-08-15T09:15:25.660 回答
1

我倾向于使用带有自定义页面适配器的 viewpager 来显示您的缩放图像视图,而不是尝试以您当前的方式进行操作。

视图寻呼机/适配器将为您处理视图回收、页面捕捉等。

于 2013-08-15T09:13:06.933 回答
0

如何使用

android:width="0"
android:weight ="1"
android:height="match_parent"

在图像视图中

和 match_parent 在您的布局中的其他位置。

于 2015-11-11T07:44:44.983 回答