Android ScrollView无法正确滚动 [英] Android ScrollView Not Scrolling Correctly

查看:111
本文介绍了Android ScrollView无法正确滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在通过newboston的android教程进行学习,但我仍然停留在数字35上.应用程序顶部应该有一个滚动条,其权重为30.代码中有6个textview/edittext字段组,但为简单起见,我删除了5个.我的问题是所有文本和文本框都出现在页面上,而不仅限于给定的重量(它们都只显示在页面上).其他人有这个问题或知道如何解决吗?

I've been making my way through thenewboston's android tutorials and I'm stuck on number 35. There is supposed to be a scroll bar that takes up a weight of 30 at the top of the app. There are 6 textview/edittext field groups in the code, but I deleted 5 for simplicity. My problem is that all of the text and text boxes appear on the page and are not confined to the given weight (they all just show up on the page). Has anyone else had this problem or know how to fix it?

请,我是stackoverflow的新手.如果您认为这是一个愚蠢的问题,请向我解释为什么以及如何可以更好地提出这个问题.

Please, I'm new to stackoverflow. If you think this is a stupid question, please explain to me why and how I can ask it better.

这是它的外观: http://imgur.com/gJmOgqk

<?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:orientation="vertical"
    android:weightSum="100" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="30" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView" />

            <EditText
                android:id="@+id/editText1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10" >
            </EditText>

        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="40"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="30"
        android:orientation="vertical" >


    <AnalogClock
        android:id="@+id/analogClock1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </LinearLayout>
</LinearLayout>

推荐答案

欢迎使用StackOverflow!

Welcome to StackOverflow!

事物,

  1. TheNewBoston犯了一个错误.每当您使用举重时,您都需要 将该元素的高度(或宽度)设置为0dp.我变了 在您的代码中.
  2. 您不应该依赖eclipse拥有的xml工具,应该始终尝试将您的应用程序启动到某种类型的设备(模拟器或硬件)上
  3. 我认为ScrollBar是ScrollView吗?因为您现在不执行任何操作来控制滚动条的外观.
  4. 布局的父级(在这种情况下)应为match_parent,而不是自动换行. (这是您的主要问题)
  5. 此外,您实际上并不需要weightSum,反正android只会将所有权重相加.

  1. TheNewBoston made a mistake. Whenever you use weights you need to set the height (or width) of that element to 0dp. I've changed that in your code.
  2. You shouldn't rely on the xml tool that eclipse has, you should always try to launch your app to some type of a device (emulator or preferably hardware)
  3. I think by ScrollBar, you mean ScrollView? Because you're not doing anything to control the appearance of the scroll bar right now.
  4. The parent of your layout (in this case) should match_parent, not wrap. (this is your main issue)
  5. Also, you don't really need weightSum, android will just sum all the weights anyway.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="30" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" >
        </EditText>

    </LinearLayout>
</ScrollView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="40"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="30"
    android:orientation="vertical" >


    <AnalogClock
        android:id="@+id/analogClock1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

这篇关于Android ScrollView无法正确滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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