【问题标题】:Auto Scroll Text In TextView在 TextView 中自动滚动文本
【发布时间】:2012-11-27 10:27:35
【问题描述】:

我有特定高度的文本视图,并且该文本视图中有很多句子。我已经在该文本视图中实现了滚动条以查看全部内容。但我想实现自动滚动,但我没有办法实现这种自动滚动。

这是我的 xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:weightSum="1"  
  >

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

</LinearLayout>

请帮我解决我的问题。谢谢。

【问题讨论】:

  • 所以滚动应该只适用于文本?
  • 检查你的代码 android:layout_width="fill_parent" android:layout_height="250dp" android:width="200dp" 这是什么?
  • 检查我上传的答案。它为我运行。检查一次并回复。

标签: android autoscroll android-scrollview android-scroll android-scrollbar


【解决方案1】:

我做了这样的事情

android:text="                                     Please take your belongings after check out."
    android:singleLine="true"
    android:textColor="#000000"

    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:layout_marginTop="150dp"
    android:scrollHorizontally="true"
    android:id="@+id/TextView03"
    android:padding="5dip" 
    android:textSize="55dp"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" />

我认为'marquee'funda 不见了........

【讨论】:

    【解决方案2】:

    一个例子:

    public class TextViewMarquee extends Activity {
        private TextView tv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            tv = (TextView) this.findViewById(R.id.tv);  
            tv.setSelected(true);  // Set focus to the textview
        }
    }
    

    在 XML 中:

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/mywidget"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:lines="1"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:textColor="#ff4500"
            android:text="this is a very long piece of text that will move" />
    </RelativeLayout>
    

    【讨论】:

      【解决方案3】:

      根据您的需要,这对我有用。

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/LinearLayout01"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical" >
      
          <ScrollView
              android:layout_width="wrap_content"
              android:layout_height="fill_parent" >
      
              <TextView
                  android:id="@+id/lyricView"
                  android:layout_width="200dp"
                  android:layout_height="250dp"
                  android:layout_marginTop="67dp"
                  android:background="#80000000"
                  android:scrollbars="vertical"
                  android:text="@string/extra"
                  android:textColor="#ffffff"
                  android:textStyle="bold" />
          </ScrollView>
      
      </LinearLayout>
      

      如果你想隐藏滚动,请使用android:scrollbars="none"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-03-09
        • 1970-01-01
        • 2018-07-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-31
        • 1970-01-01
        相关资源
        最近更新 更多