首页 > 解决方案 > 在我对我的 android 应用程序原型的模拟中,滚动视图(线性布局)没有滚动

问题描述

在我的 android 应用程序中,我在滚动视图中有一个线性布局,但是当我在模拟器中打开应用程序时,我无法滚动滚动视图。

我不知道这是否是解决方案,但我没有使用鼠标,而只是使用我的触摸板,当我尝试 2 指滚动时,模拟器的行为就像我按下按钮一样。我试图将 fillViewport 函数放入其中,但它仍然无法正常工作。

<?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=".HomeScreen">

    <Button
        android:id="@+id/settingsNavigator"
        android:layout_width="0dp"
        android:layout_height="110dp"
        android:layout_marginTop="40dp"
        android:text="SETTINGS"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="45dp"
        android:text="Not connected"
        android:textAlignment="center"
        android:textColor="#FF0000"
        android:textSize="30sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button5" />

    <Button
        android:id="@+id/button5"
        android:layout_width="0dp"
        android:layout_height="120dp"
        android:layout_marginTop="25dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ScrollView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="55dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/settingsNavigator">

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

            <Button
                android:id="@+id/button15"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:text="Button" />

            <Button
                android:id="@+id/button14"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:text="Button" />

            <Button
                android:id="@+id/button13"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:text="Button" />

            <Button
                android:id="@+id/button12"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:text="Button" />

            <Button
                android:id="@+id/button11"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:text="Button" />

            <Button
                android:id="@+id/button10"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:text="Button" />
        </LinearLayout>
    </ScrollView>

</android.support.constraint.ConstraintLayout>

应用程序构建工作正常,但滚动是唯一不工作的。

标签: javaandroid-emulatorscrollviewtouchpad

解决方案


好吧,实际上我自己很快就明白了。好像我早就问了很多这个问题而没有真正考虑过。尽管该解决方案可能对其他人有所帮助:

我只是把所有东西都放在另一个 LinearLayout 中。这解决了问题。现在只有底部在滚动,而上部保持不变,这正是我想要的。


推荐阅读