2


我有以下代码:

<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <LinearLayout android:orientation="vertical" 
                  android:layout_width="fill_parent" 
                  android:layout_height="fill_parent">

        <ImageView android:src="@drawable/ducks_r2_c1"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" />
        <ImageView android:src="@drawable/ducks_r3_c1"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" android:clickable="true"/>
        <ImageView android:src="@drawable/ducks_r4_c1"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" android:clickable="true"/>
        <ImageView android:src="@drawable/ducks_r5_c1"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" android:clickable="true"/>
        <ImageView android:src="@drawable/ducks_r6_c1"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" android:clickable="true"/>

    </LinearLayout>

</ScrollView>

我到处都使用过 layout_width="fill_parent" 。但这是它如何在模拟器上显示的屏幕截图。
在此处输入图像描述
我不想要图像两侧的空间。
为什么会出现这样的情况?我该如何纠正它?
谢谢

4

2 回答 2

1

我想这是因为图像没有拉伸。

您可以尝试让图像自行拉伸:

android:scaleType="fitXY"

或将其用作背景。

请检查这个线程: android:在imageview中拉伸图像以适应屏幕

于 2011-08-11T19:38:41.253 回答
0

ScrollView 只会膨胀到其中包含的项目数。

您应该能够通过使用 LinearLayout (或其他更可预测的布局)作为 ScrollView 的父级android:layout_height="match_parent"并将 ScrollView 设置为android:layout_height="wrap_content"和两者上的 layout_width 相同来解决此问题。

于 2011-08-11T19:35:37.233 回答