布局权重在ScrollView中不起作用 [英] Layout Weights do not work inside a ScrollView

查看:135
本文介绍了布局权重在ScrollView中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为ScrollView内部的LinearLayout中的多个项目分配布局权重.但是,ScrollView会忽略LinearLayout weightSum.

I want to assign layout weights to several items within a LinearLayout inside of a ScrollView. However, the ScrollView ignores the LinearLayout weightSum.

我的目标是用2、1、1(总和为4)的权重划分布局,但这在ScrollView内部无法正常工作.

My goal is to divide the layout with weights of 2, 1, 1 (for a total sum of 4), but this does not work properly inside of a ScrollView.

如何解决此布局问题?

main.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        android:weightSum="4">

        <LinearLayout android:id="@+id/logo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" 
            android:layout_weight="2"
            android:background="#FFFFFF" />

        <LinearLayout android:id="@+id/logo1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" 
            android:layout_weight="1"
            android:background="#000000" />


        <LinearLayout android:id="@+id/logobutton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" 
            android:layout_weight="1" 
            android:background="#4B4B4B" />

    </LinearLayout>
</ScrollView>

推荐答案

我以前遇到过此问题.只需在ScrollView中使用android:fillViewport="true",它将填满整个屏幕.

I have faced this problem before. Just use android:fillViewport="true" in your ScrollView and it will fill up the screen.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

这篇关于布局权重在ScrollView中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆