【问题标题】:Android text scrolling not working with Scrollview and TextviewAndroid 文本滚动不适用于 Scrollview 和 Textview
【发布时间】:2019-08-14 14:15:14
【问题描述】:

我一直在关注 Android CodeLab 教程并致力于 AboutMe 项目。但是当我开始制作可滚动的文本视图时,它不知何故不起作用。这是xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" android:layout_margin="8dp">
    <TextView
        android:text="@string/avra_neel"
        android:layout_width="148dp"
        android:layout_height="56dp" android:id="@+id/name_text"
        android:textAppearance="@style/TextAppearance.AppCompat.Large"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"      
        app:layout_constraintVertical_bias="0.0"
        style="@style/NameStyle"/>
      <ImageView
        android:layout_width="39dp"
        android:layout_height="44dp" 
        app:srcCompat="@android:drawable/btn_star_big_on"
        android:id="@+id/star_image" 
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp" 
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginBottom="552dp"
        app:layout_constraintBottom_toBottomOf="parent"
        android:contentDescription="@string/yellow_star" 
        android:layout_marginTop="19dp"
        app:layout_constraintTop_toBottomOf="@+id/name_text" 
        app:layout_constraintVertical_bias="0.0"/>
   <ScrollView
        android:layout_width="378dp"
        android:layout_height="473dp"
        android:scrollbars="vertical" android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent" 
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp" 
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="8dp" android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/star_image" 
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintVertical_bias="0.666"   
        android:fillViewport="true">

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

        <TextView
                android:text="@string/bio"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:id="@+id/bio_text"
                style="@style/NameStyle"
                android:textSize="28sp"
                android:paddingStart="8dp"
                android:paddingEnd="8dp"/>
    </LinearLayout>
</ScrollView>

当我尝试运行应用程序时,textview 会停留在底部或顶部,当我尝试向下滚动时,它会跳到顶部。我想我在某个地方做错了什么。 我该怎么做才能让它工作?请帮忙。

【问题讨论】:

  • 分享完整的xml

标签: android xml textview scrollview


【解决方案1】:

去掉ScrollView中的LinearLayout。
ScrollView 应该只包含 TextView

【讨论】:

    猜你喜欢
    • 2012-06-29
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多