Marquee не работает при использовании в нескольких текстовых представлениях - PullRequest
3 голосов
/ 05 марта 2012

Я использую marquee в двух разных TextViews моего виджета. Но он работает только для первого или второго TextView, когда я пытаюсь с различными комбинациями "android: focusable =" true "", android: focusableInTouchMode = "true "android: duplicateParentState =" true ".Я хочу, чтобы оба TextViews двигались.Я даю ниже код, который я использую.

<TextView
        android:id="@+id/place"
        android:layout_width="94dip"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dip"
        android:ellipsize="marquee"            
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"            
        android:lines="1"
        android:textColor="@color/white"
        android:focusable="true"
        android:focusableInTouchMode="true"
        >

        <requestFocus
            android:duplicateParentState="true"
             />
    </TextView>

    <TextView
        android:id="@+id/weather_report"
        android:layout_width="110dip"
        android:layout_height="wrap_content"
        android:layout_below="@+id/place"
        android:ellipsize="marquee"            
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:lines="1"
        android:textColor="@color/grey"
        android:focusable="true"
        android:focusableInTouchMode="true"           
        >
        <requestFocus
            android:duplicateParentState="true"
            /> 
    </TextView>

Может кто-нибудь знает решение?

Ответы [ 3 ]

2 голосов
/ 05 марта 2012

Я уверен, что вы не можете делать то, что хотите.Только выделенные виды могут «выделяться», и поскольку у вас не может быть двух сфокусированных представлений, невозможно сделать то, что вы хотите, из коробки.Однако вы можете посмотреть на startMarquee() метод в TextView и расширить пользовательский TextView, который всегда выделяется.

0 голосов
/ 01 марта 2016

В MainActivity.java,

package com.hardian.samplemarque;

import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends Activity {
TextView tvText1,tvText2;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tvText1 = (TextView)findViewById(R.id.tvText1);
    tvText2 = (TextView)findViewById(R.id.tvText2);

    tvText1.setSelected(true);
    tvText2.setSelected(true);
}

}

In activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/tvText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:scrollHorizontally="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit ="marquee_forever"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:text="1 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum" />
<TextView
    android:id="@+id/tvText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:scrollHorizontally="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit ="marquee_forever"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:text="2 It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like)." />

0 голосов
/ 05 апреля 2013

В качестве альтернативы вы также можете просто выбрать textViews. Это ставит их в фокус и активирует выделение. Работал для меня с текстовыми представлениями в listView.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...