【问题标题】:Automatic Scroll Text Within TextView AndroidTextView Android中的自动滚动文本
【发布时间】:2012-12-26 16:37:04
【问题描述】:

我正在创建具有包含大量文本的 textview 并希望执行自动垂直滚动直到文本结束的应用程序。但我没有办法执行自动滚动。

我已转发https://github.com/blessenm/SlideshowDemo 项目。 但无法使用此代码获得成功..

这是我的 XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 
 xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vertical_scrollview_id"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1.0"   
android:fadingEdge="none"
android:scrollbars="none"
 >

<LinearLayout
    android:id="@+id/vertical_outer_layout_id"
    android:layout_width="fill_parent"
    android:layout_height="350dp"
    android:orientation="vertical"
    android:layout_marginTop="67dp"
    android:paddingBottom="100dp"
   >


    <TextView
        android:id="@+id/lyricView"
        android:layout_width="fill_parent"
        android:layout_height="250dp"
        android:layout_marginTop="67dp"
        android:background="#000000"
        android:gravity="center"
        android:maxLines="16"
        android:paddingBottom="5dp"
        android:paddingTop="8dp"            
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:width="200dp" />

    <ProgressBar
        android:id="@+id/showLoading"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="-150dp"
        android:background="#000000" />
</LinearLayout>   
</ScrollView>

请给我一些想法。提前谢谢。 我的简单滚动功能运行良好。但我想执行自动垂直滚动..

【问题讨论】:

  • 但我想要自动垂直滚动。如果您有任何想法,请将代码块发送给我。
  • 你想如何自动执行你能详细说明一下吗。
  • @Dipu - 我已经编辑了我的问题。你有什么想法吗?
  • 检查stackoverflow.com/a/4546882/1777090是否自动滚动
  • 我想这会对你有所帮助Click here

标签: android android-asynctask android-scrollview autoscroll


【解决方案1】:

尝试将文本视图单独放在滚动视图中:

<ScrollView
        android:id="@+id/content_scroll"
        android:layout_width="fill_parent"
        android:layout_height="250dp"
        android:layout_margin="7dip"
        android:scrollbars="none" >
    <TextView
        android:id="@+id/lyricView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="67dp"
        android:background="#000000"
        android:gravity="center"
        android:maxLines="16"
        android:paddingBottom="5dp"
        android:paddingTop="8dp"            
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:width="200dp" />
</ScrollView>

【讨论】:

    【解决方案2】:

    当您的内容适合您的屏幕且不需要滚动视图时,它不会出现。但是当您的内容超出屏幕时,滚动视图就会出现。您必须将 textview 的 height 属性更改为 wrap_content 以使其根据内容自动增加其高度。

    试试这个:

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#e6e6fa"
        android:padding="5dp">
    
    <LinearLayout
        android:id="@+id/vertical_outer_layout_id"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="67dp"
        android:paddingBottom="100dp"
       >
    
    
        <TextView
            android:id="@+id/lyricView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="67dp"
            android:background="#000000"
            android:gravity="center"
            android:maxLines="16"
            android:paddingBottom="5dp"
            android:paddingTop="8dp"            
            android:textColor="#ffffff"
            android:textStyle="bold"
            android:width="200dp" />
    
        <ProgressBar
            android:id="@+id/showLoading"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="-150dp"
            android:background="#000000" />
    </LinearLayout>   
    </ScrollView>
    

    【讨论】:

    • 自动滚动是什么意思?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-20
    • 2014-03-09
    • 2011-07-25
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    相关资源
    最近更新 更多