当前位置 : 主页 > 手机开发 > android >

Android多个textview选框

来源:互联网 收集:自由互联 发布时间:2021-06-11
有许多textview可能有很长的文本所以已经完成 android:marqueeRepeatLimit="marquee_forever" android:ellipsize="marquee" android:singleLine="true" android:scrollHorizontally="true" android:focusable="true" android:focusableInTou
有许多textview可能有很长的文本所以已经完成

android:marqueeRepeatLimit="marquee_forever"
    android:ellipsize="marquee"
    android:singleLine="true"
    android:scrollHorizontally="true"
    android:focusable="true"
    android:focusableInTouchMode="true"

对于第一个文本视图它工作正常,但对于其他它不工作,如果有人为活动中的其他textview做了那么请帮助我.

谢谢.

使用TextView扩展您的类非常容易,并覆盖以下方法

package com.az.app;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

public class ScrollingTextView extends TextView {

    public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public ScrollingTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ScrollingTextView(Context context) {
        super(context);
    }

    // ===========================================================
    // Constants
    // ===========================================================

    // ===========================================================
    // Fields
    // ===========================================================

    // ===========================================================
    // Constructors
    // ===========================================================

    // ===========================================================
    // Getter & Setter
    // ===========================================================

    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================
    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        if (focused)
            super.onFocusChanged(focused, direction, previouslyFocusedRect);
    }

    @Override
    public void onWindowFocusChanged(boolean focused) {
        if (focused)
            super.onWindowFocusChanged(focused);
    }

    @Override
    public boolean isFocused() {
        return true;
    }
    // ===========================================================
    // Methods
    // ===========================================================

    // ===========================================================
    // Inner and Anonymous Classes
    // ===========================================================


}

并在您的XML中执行此操作

<com.az.app.ScrollingTextView
                        android:id="@+id/TextView02"
                        android:layout_width="140dp"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/ImageView01"
                        android:ellipsize="marquee"
                        android:focusable="true"
                        android:focusableInTouchMode="true"
                        android:marqueeRepeatLimit="marquee_forever"
                        android:scrollHorizontally="true"
                        android:singleLine="true"
                        android:text="This is a really very very very very very long text "
                        android:textAppearance="?android:attr/textAppearanceSmall" />
                </RelativeLayout>
<com.az.app.ScrollingTextView
                        android:id="@+id/TextView03"
                        android:layout_width="140dp"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/ImageView01"
                        android:ellipsize="marquee"
                        android:focusable="true"
                        android:focusableInTouchMode="true"
                        android:marqueeRepeatLimit="marquee_forever"
                        android:scrollHorizontally="true"
                        android:singleLine="true"
                        android:text="This is a really very very very very very long text "
                        android:textAppearance="?android:attr/textAppearanceSmall" />
                </RelativeLayout>

现在所有的textview都会滚动.

更新:请注意,没有android:singleLine =“true”它不起作用.与android:maxLines =“1”一起使用它,虽然我们知道它已被弃用.

网友评论