我在我的widget的两个不同TextView中使用选框。但是当我尝试使用“android:focusable =”true“”的不同组合时,它只用于第一个或第二个TextView,android:focusableInTouchMode =“ true“和android:duplicateParentState =”true“。我希望两个TextView都在移动。 我在下面给出了我正在使用的代码。
<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>
任何人都可以知道解决方案吗?
答案 0 :(得分:2)
我很确定你不能做你想做的事。只有专注的视图可以“选取”,因为你不能有两个专注的视图,所以你不可能做你想要的开箱即用。但是,您可以在TextView
中look at the startMarquee()
method并扩展始终使用的自定义TextView。
答案 1 :(得分:0)
或者您也可以选择textViews。这使他们成为焦点并激活大帐篷。我在listView中为文本视图工作。
答案 2 :(得分:0)
在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);
}
}
在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)." />