滚动的TextView重绘问题 [英] Scrolling TextView repaint problem

查看:474
本文介绍了滚动的TextView重绘问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,使TextView的滚动。我发现了这个问题的答案,使用特定的XML属性涉及...

I was searching for a way to make TextView scrollable. I've found an answer to this question, involving using specific XML attributes...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:orientation="vertical">
    <TextView android:layout_width="match_parent" android:layout_height="wrap_content"
        android:id="@+id/textview" android:text="The long text, which no way have chance to fit within screen's width"
        android:maxLines="1"
        android:scrollHorizontally="true" />
</LinearLayout>

...和一小片源$ C ​​$ C的...

...and a small piece of source code...

package spk.sketchbook;

import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.Gravity;
import android.widget.TextView;

public class SketchbookMain extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextView textView = (TextView)findViewById(R.id.textview);
        textView.setMovementMethod(ScrollingMovementMethod.getInstance());
    }
}

...一切的工作方式类似的魅力,但只有等到一个人试图对齐文本中的TextView的权利...

...and everything works like charm, but only until one tries to align text inside TextView to the right...

android:gravity="right|center_vertical" 

...来观察,直到用户试图滚动文本,它是无形的(可能滚出视图)。

...to observe, that until user tries to scroll the text, it is invisible (probably scrolled out of the view).

不幸的是,这正是我需要做的(使右对齐的TextView滚动)。

Unfortunately, this is just what I need to do (make right-aligned TextView scrollable).

任何想法吗?

推荐答案

这是一个不同的方法:

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:id="@+id/textview" 
        android:gravity="right|center_vertical"  
        android:text="The long text, which no way have chance to fit within screen's width"
        android:maxLines="1"/>
</HorizontalScrollView>

我认为你不需要任何code,使这项工作。

I think that you don't need any code to make this work

这篇关于滚动的TextView重绘问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆