0

所以我有一堆图像(ImageViews),我试图根据用户的设备适当地缩放。

我已经使用 weightSum 成功地对它们进行了水平缩放(4 个图像根据用户的屏幕得到同样的缩放)。

我现在正在尝试垂直缩放每一列,以便在此示例中占据屏幕的 50%,但我没有任何运气。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >



<ScrollView 
    android:layout_width="fill_parent"
    android:layout_height="500dp"
    android:scrollbars="none"
    >
    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" 
            android:weightSum="2"
    > 






        <!--  -->
        <!--  -->
        <!-- A new column -->
        <!--  -->
        <!--  -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" 
            android:weightSum="4"
            >  
            <ImageView 
                android:layout_width="0dp"
                android:layout_height="90dp" 
                android:layout_weight="1"
                android:src="@drawable/wallpaper_1"
                android:contentDescription="@string/app_name"
                android:scaleType="fitXY"
                android:layout_margin="3dp"
                android:id="@+id/wallpaper_id_1"
             />
            <ImageView 
                android:layout_width="0dp"
                android:layout_height="90dp" 
                android:layout_weight="1"
                android:src="@drawable/wallpaper_1"
                android:contentDescription="@string/app_name"
                android:scaleType="fitXY"
                android:layout_margin="3dp"
                android:id="@+id/wallpaper_id_2"
             />
            <ImageView 
                android:layout_width="0dp"
                android:layout_height="90dp" 
                android:layout_weight="1"
                android:src="@drawable/wallpaper_1"
                android:contentDescription="@string/app_name"
                android:scaleType="fitXY"
                android:layout_margin="3dp"
                android:id="@+id/wallpaper_id_3"
             />
            <ImageView 
                android:layout_width="0dp"
                android:layout_height="90dp" 
                android:layout_weight="1"
                android:src="@drawable/wallpaper_1"
                android:contentDescription="@string/app_name"
                android:scaleType="fitXY"
                android:layout_margin="3dp"
                android:id="@+id/wallpaper_id_4"
             />
        </LinearLayout>



        <!--  -->
        <!--  -->
        <!-- A new column -->
        <!--  -->
        <!--  -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" 
            android:weightSum="4"
            >  
            <ImageView 
                android:layout_width="0dp"
                android:layout_height="90dp" 
                android:layout_weight="1"
                android:src="@drawable/wallpaper_1"
                android:contentDescription="@string/app_name"
                android:scaleType="fitXY"
                android:layout_margin="3dp"
                android:id="@+id/wallpaper_id_1"
             />
            <ImageView 
                android:layout_width="0dp"
                android:layout_height="90dp" 
                android:layout_weight="1"
                android:src="@drawable/wallpaper_1"
                android:contentDescription="@string/app_name"
                android:scaleType="fitXY"
                android:layout_margin="3dp"
                android:id="@+id/wallpaper_id_2"
             />
            <ImageView 
                android:layout_width="0dp"
                android:layout_height="90dp" 
                android:layout_weight="1"
                android:src="@drawable/wallpaper_1"
                android:contentDescription="@string/app_name"
                android:scaleType="fitXY"
                android:layout_margin="3dp"
                android:id="@+id/wallpaper_id_3"
             />
            <ImageView 
                android:layout_width="0dp"
                android:layout_height="90dp" 
                android:layout_weight="1"
                android:src="@drawable/wallpaper_1"
                android:contentDescription="@string/app_name"
                android:scaleType="fitXY"
                android:layout_margin="3dp"
                android:id="@+id/wallpaper_id_4"
             />
        </LinearLayout>




    </LinearLayout>
</ScrollView>


</LinearLayout>

以前有人处理过这个吗?谢谢

4

1 回答 1

3

For the first LinearLayout inside your ScrollView, height of wrap_content doesn't make sense if you're using weights. Use fill_parent or match_parent instead. That said, it doesn't exactly make sense to have a ScrollView around something like that and additionally nested weights tend to yield poor performance. You might want to consider using GridView instead.

于 2012-08-28T00:26:17.587 回答