Scrollview超出了屏幕底部 [英] Scrollview extends beyond screen bottom

查看:134
本文介绍了Scrollview超出了屏幕底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我突然遇到一个问题,即Scrollview超出了屏幕底部,因此即使您一直向下滚动,它也不会显示其所有内容. XML是:

I suddenly have the problem that Scrollview extends beyond the bottom of the screen so that even if you scroll all the way down it does not show all its content. The XML is:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFFFF">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:background="#FFBBBBBB"
        android:orientation="vertical" >
        <View
            android:layout_width="100dp"
            android:layout_height="300dp"
            android:layout_margin="15dp"
            android:layout_gravity="center_horizontal"
            android:background="#FFDDDDFF"/>
        <View
            android:layout_width="100dp"
            android:layout_height="300dp"
            android:layout_margin="15dp"
            android:layout_gravity="center_horizontal"
            android:background="#FFDDDDFF"/>
    </LinearLayout>
</ScrollView>

没有比这更简单的了.一直向下滚动(如滚动条的形状所示)后,您应该会看到底部的白色边距,但这是它的样子:

It doesn't get any simpler than that. Once you have scrolled all the way down (as indicated by the shape of the scroller) you should see the bottom white margin but instead this is what it looks like:

与顶部比较:

底部应该看起来像顶部,只是颠倒了.这发生在模拟器,真实设备以及我尝试过的几乎每个Android版本中.我不知道自己在做什么错(如果有的话...).

The bottom should look like the top, only reversed. This happens in the emulator, on real devices and in pretty much every Android version I have tried. I am at a loss as to what I am doing wrong (if anything...).

请不要猜测,也不要从臀部射击!仅测试答案.我已经在这上面浪费了足够的时间.谢谢.

Please no guesses and no shooting from the hip! Only tested answers. I wasted enough time on this already as it is. Thanks.

推荐答案

在死胡同上浪费了很多时间后,我终于被这个

After wasting much time in dead alleys I was finally put on the right track by this other SO thread: the issue was the layout margin on the LinearLayout. Apparently ScrollView doesn't like that, just as it doesn't like its child to be centered (an issue flagged by many other people but not my problem here) and who knows what else. Very choosy widget. It's issues like this that make me reconsider my commitment to Android: it's just too time-consuming relative to alternative platforms and, even if you enjoy the challenge, time is money.

无论如何,为了让以后在这里失败的人受益,这是一个并行的演示,左侧显示了一个破碎的布局(上面版本的更简单的版本),而右侧是一个有效的布局.诀窍是通过在额外容器上填充来模仿木ver边缘.

Anyway, for the benefit of those who will flop here later, here is a side-by-side demonstration of a broken layout (a simpler version of the one above) on the left and a working one on the right. The trick is to emulate the verboten margin with padding on an extra container.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#00FFFF"
    android:orientation="horizontal"
    android:baselineAligned="false">
    <ScrollView        
        android:layout_width="0dp"
        android:layout_weight="1"    
        android:layout_height="match_parent"
        android:background="#FFFFFFFF">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"
            android:background="#FFBBBB22"
            android:orientation="vertical">
            <View
                android:layout_width="100dp"
                android:layout_height="1000dp"
                android:layout_margin="15dp"
                android:layout_gravity="center_horizontal"
                android:background="#FFDDDDFF"/>
        </LinearLayout>
    </ScrollView>
    <View 
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="#FF000000"/>
    <ScrolllView 
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="match_parent"
        android:background="#FFFFFFFF">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:background="#FFFFFF"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#FFBBBB22"
                android:orientation="vertical">
                <View
                    android:layout_width="100dp"
                    android:layout_height="1000dp"
                    android:layout_margin="15dp"
                    android:layout_gravity="center_horizontal"
                    android:background="#FFDDDDFF"/>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

这篇关于Scrollview超出了屏幕底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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