如何使用weightSum来垂直和水平缩放(我的不工作)android

如何使用weightSum来垂直和水平缩放(我的不工作)android,android,android-linearlayout,Android,Android Linearlayout,因此,我有一组图像(ImageView),我正试图根据用户的设备进行适当的缩放 我已经成功地使用weightSum水平缩放了它们(根据用户的屏幕,4幅图像的比例相等) 我现在尝试垂直缩放每个列,以便在本例中它占据屏幕的50%,但我没有任何运气 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android

因此,我有一组图像(ImageView),我正试图根据用户的设备进行适当的缩放

我已经成功地使用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>

以前有人处理过吗?
感谢您在ScrollView中的第一个线性布局,
wrap\u内容的高度如果您使用的是权重,则没有意义。使用
填充父项
匹配父项
。也就是说,围绕这样的东西使用滚动视图是没有意义的,另外嵌套的权重往往会产生较差的性能。你可能想考虑使用.< /p> 对于滚动视图中的第一个线性布局,如果使用权重,WrAPHythult的高度就没有意义了。使用
填充父项
匹配父项
。也就是说,围绕这样的东西使用滚动视图是没有意义的,另外嵌套的权重往往会产生较差的性能。你可能想考虑使用它。

也是的,我知道我在滚动视图中拥有这一切,这背后的原因是因为最终我希望添加15个+列。我只是想根据用户的设备来缩放每个图像。在平板电脑上,一些50dp高的设备看起来很不错,不过那会非常小。这就是为什么我想使用weight sum。是的,我知道我在一个scrollview中拥有所有这些,这背后的原因是因为最终我希望添加15个以上的列。我只是想根据用户的设备来缩放每个图像。在平板电脑上,一些50dp高的设备看起来很不错,不过那会非常小。这就是为什么我想使用权重。现在我想起来了,使用滚动视图是没有意义的。其背后的逻辑是,我想显示一组图像,但我也希望它们能够根据设备进行缩放。即使它与权重和的大小相矛盾,我还是希望它们比全屏更大,这样你就可以在它们之间滚动。所以缩略图会很大,在我看来比一个典型的缩略图要大。现在我想了想,使用scrollview真的没有意义。其背后的逻辑是,我想显示一组图像,但我也希望它们能够根据设备进行缩放。即使它与权重和的大小相矛盾,我还是希望它们比全屏更大,这样你就可以在它们之间滚动。所以拇指指甲会很大,在我看来比一般的拇指指甲大。