ScrollView内边距

4

我正在尝试在ScrollView中使用ImageView。

我的xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:layout_gravity="right" >

        <ImageView
            android:id="@+id/tapjoy_dialog_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:src="@drawable/untitled" />

</ScrollView>

奇怪的是,当我运行它时,图像顶部和底部有非常宽的填充。要了解我的意思,请查看我附上的屏幕截图。
如何解决这个问题?
更奇怪的是:
1. 当我删除ScrollView,只保留ImageView时,它不会填充并且工作得很好。 2. 当我删除ImageView并放置一个大的textView时,它也不会填充并且工作得很好。
因此,我认为问题与ScrollView和ImageView的组合有关...
我尝试放入ImageView的图片如下所示:

你的意思是什么?只需要用RelativeLayout包装ImageView吗? 如果是这样,我现在已经尝试了,但它不起作用... - user1028741
删除 android:fillViewport="true" 或将其设置为 false 并运行。 - Padma Kumar
实际上,一开始我尝试了没有使用fillViewport,后来加上它是为了尝试操作ScrollView使其正常工作... 但它并没有起作用... - user1028741
2个回答

7
android:adjustViewBounds="true"添加到你的ImageView中。

1
谢谢,我在这个问题上花了好几个小时,你的一行回答解决了我的问题... :) - user1028741

0

//为你的滚动视图添加一个父布局

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:fillViewport="false"
    android:layout_gravity="right" >
<LinearLayout  android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        <ImageView
            android:id="@+id/tapjoy_dialog_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:src="@drawable/untitled" />

</LinearLayout>
</ScrollView>

@user1028741 修改 android:fillViewport="false" - Padma Kumar
我尝试移除fillViewport - 但它没有改变任何东西 - 仍然是同样的情况... - user1028741
抱歉,我不明白你的意思? 结果ScrollView的图像?我在问题中附上了它。 你能解释一下你指的是哪个图像吗? - user1028741
我想要 android:src="@drawable/untitled,所以我会在这里尝试。 - Padma Kumar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接