【问题标题】:ScrollView padding滚动视图填充
【发布时间】:2012-02-07 13:49:25
【问题描述】:

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

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

我该如何解决这个问题?

更奇怪的是:

  1. 当我删除 ScrollView 并仅保留 ImageView 时,它无法很好地填充和工作。

  2. 当我删除 ImageView 并放置一个大的 textView 时,它也不能很好地填充和工作。

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

我尝试放入 ImageView 的图像是这样的:

【问题讨论】:

  • 什么意思?只是用RelativeLayout 包装ImageView?如果是这样,我现在尝试了,它不起作用......
  • 删除 android:fillViewport="true" 或将其设置为 false 并运行它。
  • 其实一开始我是在没有fillViewport的情况下尝试的,我添加它是为了尝试操纵ScrollView使其正常工作......它不起作用......

标签: android android-imageview android-scrollview


【解决方案1】:

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

【讨论】:

  • 谢谢你,我花了几个小时在这件事上,你的单行回答成功了...... :)
【解决方案2】:

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

<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"
  • 我尝试删除 fillViewort - 它没有改变任何东西 - 仍然是一样的......
  • 对不起,我没明白你的意思?结果 ScrollView 的图像?我在问题中附上了它。你能解释一下你指的是什么图片吗?
  • 我想要 android:src="@drawable/untitled 这样我就在这里试试。
猜你喜欢
  • 2021-10-26
  • 2012-03-27
  • 2013-10-27
  • 2011-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多