【问题标题】:how to center an image inside a scrollview and horizontal scroll view android如何在滚动视图和水平滚动视图android中居中图像
【发布时间】:2015-08-18 17:27:54
【问题描述】:

我正在使用 picasso 将大图像加载到 imageview 中,但我希望它位于视图的中心,但现在它与开始(左上角)对齐,我通过 xml 尝试了alsorts,但没有成功,图像视图在这样的滚动视图和水平滚动视图中

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

有些图像在水平方向上对屏幕来说太大了,有些在垂直方向上太大了,所以我遇到了一种以编程方式实现它的方法,但它不起作用我尝试使用滚动视图的宽度和高度,这不起作用所以我尝试获取像这样的图像视图的高度和宽度,

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

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

【问题讨论】:

    标签: android image uiscrollview picasso horizontalscrollview


    【解决方案1】:

    试试这个布局:

    <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

    【讨论】:

    • 不工作太大的图像(比设备屏幕高,比设备屏幕宽)仍然从左上角开始这些视图嵌套在设置为填充父级的框架布局中,但我不明白这是怎么回事可能会影响它
    • 把它拿出来做成顶视图但没有区别
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    相关资源
    最近更新 更多