【问题标题】:Android scrollview shrinks imageviewAndroid scrollview 缩小 imageview
【发布时间】:2011-12-27 08:45:02
【问题描述】:

这是我的 layout xmlRelativelayoutScrollview:-

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

    <RelativeLayout
        android:id="@+id/layout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp" >

        <View
            android:id="@+id/separator1"
            android:layout_width="fill_parent"
            android:layout_height="3dp"
            android:background="@android:color/white" />

        <TextView
            android:id="@+id/title"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/separator1"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:text="Merry Xmas"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textStyle="bold" />

        <View
            android:id="@+id/separator2"
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_below="@+id/title"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:background="@android:color/white" />

        <ImageView
            android:id="@+id/image1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@+id/separator2"
            android:scaleType="fitCenter" />

        <View
            android:id="@+id/separator3"
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_below="@+id/image1"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:background="@android:color/white" />

        <TextView
            android:id="@+id/text2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/separator3"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:text="Happy New Year"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textStyle="bold" />
    </RelativeLayout>
</ScrollView>

这是我的问题:-

  • 如果我删除ScrollView 标签,ImagView 会拉伸并填充宽度,这正是我想要的。
  • 如果我添加ScrollView 标签,它会出于某种原因缩小ImagView

任何想法如何应用ScrollView 并让ImageView 填满宽度?

【问题讨论】:

    标签: android imageview scrollview


    【解决方案1】:

    您是否尝试过将 RealtiveLayout 设置为填充父级?我也注意到有时RelativeLayout 会缩小imageViews。也许您可以尝试使用 LinearLayout。

    【讨论】:

    • 尝试了您建议的所有方法,结果相同。
    • 如果只将 ImageView 添加到 ScrollView 中会缩小吗?如果是,则 ScrollView 可能具有默认填充,您可以将其设置为零。同样使用 ImageView android:scaleType="fitCenter" 您可以尝试不同的设置。我没有你的图片来试验自己...
    • 是的,如果只是滚动视图中的图像视图,它会缩小图像。我摆脱了 android:scaleType,尝试为 scrollview 和 imageview 设置 android:padding="0dp",仍然没有。
    • fillViewPort=true 给了我正确的大小,但随后滚动被禁用。
    • 您是否以编程方式在图像视图中加载图像?因为如果 ImageView 预加载图像,您的布局可以正常工作: android:src="@drawable/my_image"
    猜你喜欢
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-25
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    相关资源
    最近更新 更多