无法弄清楚为什么scrollview不滚动 [英] Can't figure out why scrollview is not scrolling

查看:103
本文介绍了无法弄清楚为什么scrollview不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的转换器应用程序.尝试转换输入并将其显示在下面的EditTexts中,但是我的ScrollView无法正常工作.(实际上什么也没做)我将ConstraintLayout用作根,并在其中包含LinearLayout,它是ScrollView的根.

那么,我在这里想念什么?

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="gns.converter.LengthConversion">

    <Spinner
        android:id="@+id/spinnerTo"
        android:layout_width="120dp"
        android:entries="@array/spinnerLengthItems"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@+id/textFrom"
        android:layout_marginLeft="42dp"
        app:layout_constraintBaseline_toBaselineOf="@+id/textFrom"
        android:layout_marginStart="42dp" />

    <EditText
        android:id="@+id/textFrom"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number"
        android:textSize="20sp"
        android:hint="(From) 0"
        android:gravity="right"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="44dp"
        android:layout_marginLeft="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginStart="16dp" />


    <Button
        android:id="@+id/buttonConvert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="78dp"
        android:layout_marginTop="13dp"
        android:text="CONVERT"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textFrom"
        android:layout_marginStart="78dp" />

    <Button
        android:id="@+id/buttonClear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="42dp"
        android:layout_marginTop="23dp"
        android:text="CLEAR"
        app:layout_constraintLeft_toRightOf="@+id/buttonConvert"
        app:layout_constraintTop_toBottomOf="@+id/spinnerTo"
        android:layout_marginStart="42dp" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="495dp"
        android:orientation="horizontal"
        android:layout_marginRight="8dp"
        android:background="#e40707"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginTop="30dp"
        app:layout_constraintTop_toBottomOf="@+id/buttonConvert"
        app:layout_constraintHorizontal_bias="0.0">


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            >

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

                <EditText
                    android:id="@+id/editText2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText6"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText7"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText8"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText9"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />
            </LinearLayout>




        </ScrollView>
    </LinearLayout>


</android.support.constraint.ConstraintLayout>

解决方案

尝试使您的滚动视图android:fillViewport="true"

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">
  // add here all your controls
</LinearLayout>

</ScrollView>

I'm making a simple converter app. Trying to convert input and display it in the EditTexts below but my ScrollView doesnt work.(Literally does nothing) I use ConstraintLayout as root and I have LinearLayout inside it which is the root of ScrollView.

So, What am I missing here?

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="gns.converter.LengthConversion">

    <Spinner
        android:id="@+id/spinnerTo"
        android:layout_width="120dp"
        android:entries="@array/spinnerLengthItems"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@+id/textFrom"
        android:layout_marginLeft="42dp"
        app:layout_constraintBaseline_toBaselineOf="@+id/textFrom"
        android:layout_marginStart="42dp" />

    <EditText
        android:id="@+id/textFrom"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number"
        android:textSize="20sp"
        android:hint="(From) 0"
        android:gravity="right"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="44dp"
        android:layout_marginLeft="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginStart="16dp" />


    <Button
        android:id="@+id/buttonConvert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="78dp"
        android:layout_marginTop="13dp"
        android:text="CONVERT"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textFrom"
        android:layout_marginStart="78dp" />

    <Button
        android:id="@+id/buttonClear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="42dp"
        android:layout_marginTop="23dp"
        android:text="CLEAR"
        app:layout_constraintLeft_toRightOf="@+id/buttonConvert"
        app:layout_constraintTop_toBottomOf="@+id/spinnerTo"
        android:layout_marginStart="42dp" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="495dp"
        android:orientation="horizontal"
        android:layout_marginRight="8dp"
        android:background="#e40707"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginTop="30dp"
        app:layout_constraintTop_toBottomOf="@+id/buttonConvert"
        app:layout_constraintHorizontal_bias="0.0">


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            >

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

                <EditText
                    android:id="@+id/editText2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText6"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText7"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText8"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />

                <EditText
                    android:id="@+id/editText9"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:text="Name" />
            </LinearLayout>




        </ScrollView>
    </LinearLayout>


</android.support.constraint.ConstraintLayout>

解决方案

try this make your scroll view android:fillViewport="true"

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">
  // add here all your controls
</LinearLayout>

</ScrollView>

这篇关于无法弄清楚为什么scrollview不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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