android ScrollView指向视图的中心

问题描述

| 在我的应用程序中,我正在使用ScrollView来显示图像。 有时候,当图像比视图大时,我要显示图像的正中央,然后将图像滚动到其边缘。 ScrollView包含一个ImageView容器。 怎么做? 谢谢, 没错
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout
  xmlns:android=\"http://schemas.android.com/apk/res/android\"
  android:layout_width=\"match_parent\"
  android:layout_height=\"match_parent\">

    <RelativeLayout android:id=\"@+id/relativeLayout1\" 
        android:layout_height=\"match_parent\" 
        android:layout_width=\"match_parent\">

        <ScrollView android:id=\"@+id/scrollView1\" 
            android:layout_height=\"wrap_content\" 
            android:layout_width=\"wrap_content\"
            android:layout_weight=\"1.0\">

            <ImageView android:id=\"@+id/imgImageView\" 
                android:layout_height=\"wrap_content\"  
                android:layout_alignParentLeft=\"true\" 
                android:layout_width=\"wrap_content\" 
                android:layout_gravity=\"center\"/>

        </ScrollView>

        <TextView android:layout_height=\"wrap_content\" 
            android:id=\"@+id/addrTextView\" 
            android:layout_alignParentBottom=\"true\" 
            android:layout_width=\"match_parent\" 
            android:gravity=\"center\"
            android:textSize=\"12px\"
            android:layout_weight=\"0.0\"/>
    </RelativeLayout>

</LinearLayout>
    

解决方法

        在ImageView中
android:layout_centerInParent=\"true\"