ScrollView填充

时间:2012-02-07 13:49:26

标签: android android-imageview android-scrollview

我正在尝试使用带有ImageView的ScrollView。 我的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>

奇怪的是,当我运行它时,图像显示在它的顶部和底部有一个非常宽的填充。要了解我的意思,请查看我附上的屏幕截图。

ScrollView snapshot

我该如何解决这个问题?

更奇怪的是:

  1. 当我删除ScrollView并仅保留ImageView时,它不会填充并且工作正常。

  2. 当我删除I​​mageView并放置一个大的textView时,它也不会填充并且工作得很好。

  3. 所以,我认为这个问题与ScrollView和ImageView的组合有点相关......

    我尝试放入ImageView的图像是这样的: enter image description here

2 个答案:

答案 0 :(得分:6)

android:adjustViewBounds="true"添加到您的ImageView

答案 1 :(得分: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>