Image margins are cut in the scrollview

本秂侑毒 提交于 2019-12-08 14:19:48

问题


My android app contains a map that the user should scroll horizontally and vertically to see all of it. I've used two horizontal and vertical scroll view, and the image view is in it. But the problem is that, the picture isn't shown completely in the layout and a part of the top margin and left margin are hidden(cut). so my question is:

  1. How to show the picture completely in the scroll view without cutting the margins?The problem is shown is this picture
  2. when I start the application at first the image in the scroll view is not scaled! and after a touch event gets bigger at its size.

code:

 <HorizontalScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="100dp"
    android:layout_marginTop="150dp"
    android:scrollbarStyle="outsideOverlay"
    >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center"
        android:gravity="center">

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scrollbarStyle="outsideOverlay">

           <RelativeLayout
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:orientation="vertical"
               android:layout_gravity="center"
               android:gravity="center">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:srcCompat="@android:drawable/ic_input_add"
                    android:id="@+id/imageView2"

                    android:gravity="center_vertical|center_horizontal"
                    />

           </RelativeLayout>
        </ScrollView>

    </RelativeLayout>
</HorizontalScrollView>

回答1:


Try changing the width and height of outer Relative Layout to match parent. Your updated code should be like this:

<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp"
android:layout_marginTop="150dp"
android:scrollbarStyle="outsideOverlay"
>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbarStyle="outsideOverlay">

       <RelativeLayout
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_gravity="center"
           android:gravity="center">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:srcCompat="@android:drawable/ic_input_add"
                android:id="@+id/imageView2"

                android:gravity="center_vertical|center_horizontal"
                />

       </RelativeLayout>
    </ScrollView>

</RelativeLayout>



来源:https://stackoverflow.com/questions/43777195/image-margins-are-cut-in-the-scrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!