如何将图像置于scrollview和水平滚动视图android中

时间:2015-08-18 17:27:55

标签: android image uiscrollview picasso horizontalscrollview

我正在使用毕加索将大图像加载到imageview中,但我想让它坐在视图的中心,但是现在它与开始(左上角)对齐我已经通过xml尝试过多而没有成功,图像视图在滚动视图内部和像这样的水平滚动视图

  <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/scrollcontainer">

        <HorizontalScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/upydownyscrolleyscrolley">

            <ScrollView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/leftyrightyscrolleyscrolley"
                >
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:id="@+id/imagecontainer">

                <ImageView
                    android:id="@+id/wallImage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                </LinearLayout>

            </ScrollView>
        </HorizontalScrollView>
    </RelativeLayout>

有些图像对于屏幕水平太大而有些图像太垂直,所以我遇到了一种方式来实现它以编程方式但它不工作我尝试使用scrollviews的宽度和高度,这没有工作所以我试图得到像这样的图像视图的高度和宽度,

int centerX = WallpaperView.getWidth()/2;
int centerY = WallpaperView.getHeight()/2;
scrollView.scrollTo(centerX, centerY);

但又一次没有快乐,我不知道这是因为毕加索还没有加载视图,虽然我在调用毕加索后调用它是否有人可以帮助我?

1 个答案:

答案 0 :(得分:0)

试试这个布局:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/scrollcontainer">

    <HorizontalScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/upydownyscrolleyscrolley">

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/leftyrightyscrolleyscrolley">

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="horizontal"
                android:id="@+id/imagecontainer">

            <ImageView
                android:id="@+id/wallImage"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:scaleType="centerInside"
                android:gravity="center" />

            </LinearLayout>

        </ScrollView>
    </HorizontalScrollView>
</RelativeLayout>

如需更多帮助,请查看:http://etcodehome.blogspot.com/2011/05/android-imageview-scaletype-samples.html

相关问题