本文介绍了如何小规模的ImageView填补大型滚动型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建与在缩放到适合整个滚动视图,并滚动一个ImageView的有一个小图像的画面填充滚动型的布局?例如。一个720x1280显示器具有全屏幕滚动视图(FILL_PARENT)。里面是一个的LinearLayout(FILL_PARENT)。在这是一个300x900位图中被放大后,以720x2160一个imageview的,充满屏幕宽度和超过垂直边界,并且可以在滚动视图/向下向上滚动

How do you create a layout with a screen-filling scrollview that has a small image in an imageview scaled to fit the whole scrollview and be scrollable? eg. A 720x1280 display has a full-screen scrollview (fill_parent). Inside is a linearlayout (fill_parent). In that is a 300x900 bitmap in an imageview that is upscaled to 720x2160, fills the screen width and exceeds the vertical bounds, and can be scrolled up/down in the scrollview.

该解决方案应该为所有屏幕尺寸合作,支持从移动多个设备到平板电脑。

The solution should work for all screen sizes to support multiple devices from mobiles to tablets.

推荐答案

这对我的作品:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:layout_width="720dp"
            android:layout_height="2160dp"
            android:src="@drawable/image"
            android:scaleType="fitXY"/>

    </LinearLayout>

</ScrollView>

如果您需要,使这项工作任何屏幕尺寸做到这一点编程方式:

If you need to make this work for any screen size do it programmatically:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageView = (ImageView) findViewById(R.id.imageView);

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    imageView.getLayoutParams().width = width;
}

这篇关于如何小规模的ImageView填补大型滚动型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 19:49