我正在创建具有大量文本的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>
Pleaze给我一些想法。 Thanx提前。 我的简单滚动功能很好用。但我想执行自动垂直滚动..
答案 0 :(得分:1)
尝试将文本视图单独放在scrollview中:
<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>
答案 1 :(得分:1)
如果您的内容适合不需要滚动视图的屏幕,则不会显示。但是当您的内容超出屏幕时,滚动视图就会出现。您必须将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>