如何在Android应用程序中使用字幕文本?
答案 0 :(得分:119)
以下是一个例子:
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.mywidget);
tv.setSelected(true); // Set focus to the textview
}
}
带有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:maxLines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use marquee, with a long text" />
</RelativeLayout>
答案 1 :(得分:23)
TextView textView = (TextView) this.findViewById(R.id.textview_marquee);
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setText("General Information... general information... General Information");
textView.setSelected(true);
textView.setSingleLine(true);
答案 2 :(得分:22)
android:ellipsize="marquee"
这仅适用于TextView
有焦点的情况。
答案 3 :(得分:10)
为了实现这一点,我必须使用已提到的所有三项内容(ellipsize,selected和singleLine):
TextView tv = (TextView)findViewById(R.id.someTextView);
tv.setSelected(true);
tv.setEllipsize(TruncateAt.MARQUEE);
tv.setSingleLine(true):
答案 4 :(得分:8)
Xml代码
<TextView
android:id="@+id/txtTicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true"
android:gravity="center_horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:scrollHorizontally="true"
android:shadowColor="#FF0000"
android:shadowDx="1.5"
android:shadowDy="1.3"
android:shadowRadius="1.6"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold" >
</TextView>
爪哇
txtEventName.setSelected(true);
如果文字较小,则在文字
之前和之后添加空格txtEventName.setText("\t \t \t \t \t \t"+eventName+"\t \t \t \t \t \t");
答案 5 :(得分:8)
将这些参数放到TextView中 - 它的工作原理:D
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
您还需要setSelected(true)
:
my_TextView.setSelected(true);
问候, 克里斯托弗
答案 6 :(得分:6)
我建议使用Webview如果要水平移动短字符串。 Main_Activity.java代码:`
WebView webView;
webView = (WebView)findViewById(R.id.web);
String summary = "<html><FONT color='#fdb728' FACE='courier'><marquee behavior='scroll' direction='left' scrollamount=10>"
+ "Hello Droid" + "</marquee></FONT></html>";
webView.loadData(summary, "text/html", "utf-8"); // Set focus to the textview
`
main_activity.xml代码:
<WebView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/web"
></WebView>
&#13;
答案 7 :(得分:2)
除了droidgren识别的XML设置外,我的测试表明,如果要显示的文本比textview的宽度短,那么选取框根本不会滚动。可能的解决方案是将视图的宽度设置为小于文本长度的大小,或者将字符串连接到自身2或3次,中间可能有适当的空格,以便滚动看起来正常。
答案 8 :(得分:2)
在XML中添加以下代码
<TextView
android:text="Shops NearBy textdf fsdgsdgsdg dsgtsgsdgsdgsg"
android:id="@+id/txtEventName"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:singleLine="true"/>
在Java中添加以下代码:
TextView txtEventName=(TextView)findViewById(R.id.txtEventName);
txtEventName.setSelected(true);
答案 9 :(得分:1)
用它来设置Marque:
final TextView tx = (TextView) findViewById(R.id.textView1);
tx.setEllipsize(TruncateAt.MARQUEE);
tx.setSelected(true);
tx.setSingleLine(true);
tx.setText("Marquee needs only three things to make it run and these three things are mentioned above.");
您不需要将“ android:marqueeRepeatLimit =”marquee_forever “用于xml文件。即使没有这个,Marquee也能正常工作。
答案 10 :(得分:1)
在XML文件中,您需要在TextView中添加以下附加属性才能获得类似于字幕的功能:
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
在MainActivity.java文件中,您可以使用findViewById()获取此TextView的引用,并且可以将以下属性设置为此TextView,使其看起来像一个选框文本:
setSelected(true);
这就是你所需要的一切。
答案 11 :(得分:1)
我已经尝试了以上所有,但对我来说它没有用。 当我添加
android:clickable="true"
然后它对我来说很完美。我不知道为什么。但我很乐意去做。
以下是我的完整答案。
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
答案 12 :(得分:0)
您可以使用TextView或自定义TextView。 后者是文本视图无法始终聚焦的时候。
首先,您可以使用TextView或自定义TextView作为布局.xml文件中的滚动文本视图,如下所示:
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@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;
}
}
注意:在上面的代码片段中,com.example.myapplication是一个示例包名称,应该用您自己的包名替换。
然后,在使用CustomTextView的情况下,您应该定义CustomTextView类:
here is my code:
public class AbstractActivity extends AppCompatActivity implements View.OnClickListener{
private String[] mPlanetTitles;
private LinearLayout mDrawerList;
protected DrawerLayout mDrawerLayout;
protected ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
protected Toolbar toolbar;
protected FrameLayout mFrameLayout;
LinearLayout list0,list1,list2,list3,list4,list5,list6,list7,list8,list9,list10,list11,list12,list13,list14;
FancyButton btnAdd,btnChange;
private TextView txtUserName,txtUserDob,txtUserPlace;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_abstract);
mFrameLayout = (FrameLayout)findViewById(R.id.main_activity_content_frame);
txtUserName.findViewById(R.id.txtUserName);
txtUserDob.findViewById(R.id.txtUserDob);
txtUserPlace.findViewById(R.id.txtUserLocation);
SharedPreferences sharedPreferences = getSharedPreferences(Const.Shared.MY_PREFERNCES,MODE_PRIVATE);
String name = sharedPreferences.getString(Const.Shared.USER_NAME,null);
int day = sharedPreferences.getInt(Const.Shared.DAY,0);
int month = sharedPreferences.getInt(Const.Shared.MONTH,0);
int year = sharedPreferences.getInt(Const.Shared.YEAR,0);
String location = sharedPreferences.getString(Const.Shared.LOCATION,null);
txtUserName.setText(name);
txtUserDob.setText(day+"-"+month+"-"+year);
txtUserPlace.setText(location);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.main_activity_DrawerLayout);
//mDrawerList = (LinearLayout) findViewById(R.id.left_drawer);
mTitle = mDrawerTitle = getTitle().toString();
mDrawerLayout.closeDrawers();
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
toolbar, R.string.drawer_open, R.string.drawer_close){
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getSupportActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// Disables the burger/arrow animation by default
super.onDrawerSlide(drawerView, 0);
}
};
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
mDrawerToggle.syncState();
mDrawerLayout.setDrawerListener(mDrawerToggle);
//View frameNavigation = findViewById(R.id.fram)
list0 =(LinearLayout)findViewById(R.id.listm0);
list1 =(LinearLayout)findViewById(R.id.listm1);
list2 =(LinearLayout)findViewById(R.id.listm2);
list3 =(LinearLayout)findViewById(R.id.listm3);
list4 =(LinearLayout)findViewById(R.id.listm4);
list5 =(LinearLayout)findViewById(R.id.listm5);
list6 =(LinearLayout)findViewById(R.id.listm6);
list7 =(LinearLayout)findViewById(R.id.listm7);
list8 =(LinearLayout)findViewById(R.id.listm8);
list9 =(LinearLayout)findViewById(R.id.listm9);
list10 =(LinearLayout)findViewById(R.id.listm10);
list11 =(LinearLayout)findViewById(R.id.listm11);
list12 =(LinearLayout)findViewById(R.id.listm12);
list13 =(LinearLayout)findViewById(R.id.listm13);
list14 =(LinearLayout)findViewById(R.id.listm14);
btnAdd =(FancyButton)findViewById(R.id.btn_add);
btnChange =(FancyButton)findViewById(R.id.btn_change);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
int items = item.getItemId();
switch(items){
case R.id.action_Contact_us:{
Intent intent = new Intent(this,Contact.class);
startActivity(intent);
}break;
case R.id.action_Aboutus:{
Intent intent = new Intent(this,AboutUs.class);
startActivity(intent);
}break;
case R.id.action_Profile:{
Intent intent = new Intent(this,HoroscopeChart.class);
startActivity(intent);
}break;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
}
public void myclick(View v){
int id = v.getId();
switch (id) {
case R.id.btn_add: {
Intent intent = new Intent(this, Form.class);
startActivity(intent);
}break;
case R.id.btn_change: {
Intent intent = new Intent(this, Form.class);
startActivity(intent);
}break;
case R.id.listm0: {
Intent intent = new Intent(this, DailyPrediction.class);
startActivity(intent);
}
break;
case R.id.listm1: {
Intent intent = new Intent(this, AstroDetailsMain.class);
startActivity(intent);
}
break;
case R.id.listm2: {
Intent intent = new Intent(this, HoroscopeChart.class);
startActivity(intent);
}
break;
case R.id.listm3: {
Intent intent = new Intent(this, PlanetaryPositions.class);
startActivity(intent);
}
break;
case R.id.listm4: {
Intent intent = new Intent(this, VimshottariDashaMain.class);
startActivity(intent);
}
break;
case R.id.listm5: {
Intent intent = new Intent(this, YoginiDashaMain.class);
startActivity(intent);
}
break;
case R.id.listm6: {
Intent intent = new Intent(this, ChardashaMain.class);
startActivity(intent);
}
break;
case R.id.listm7: {
Intent intent = new Intent(this, AshtakVarga.class);
startActivity(intent);
}
break;
case R.id.listm8: {
Intent intent = new Intent(this, Kalsarp.class);
startActivity(intent);
}
break;
case R.id.listm9: {
Intent intent = new Intent(this, Manglik.class);
startActivity(intent);
}
break;
case R.id.listm10: {
Intent intent = new Intent(this, PitraDosha.class);
startActivity(intent);
}
break;
case R.id.listm11: {
Intent intent = new Intent(this, Sadhesati.class);
startActivity(intent);
}
break;
case R.id.listm12: {
Intent intent = new Intent(this, AscendantReport.class);
startActivity(intent);
}
break;
case R.id.listm13: {
Intent intent = new Intent(this, HouseReports.class);
startActivity(intent);
}
break;
case R.id.listm14: {
Intent intent = new Intent(this, SignReport.class);
startActivity(intent);
}
break;
}
}
}
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_activity_DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- The main content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/kundli_toolbar" />
<FrameLayout
android:id="@+id/main_activity_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- The navigation drawer -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fancy="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:clipToPadding="false"
android:paddingBottom="10dp"
android:paddingTop="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fancy="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/png"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp">
<TextView
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtUserName"
android:textColor="@android:color/white"
android:textSize="22dp"/>
<TextView
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:id="@+id/txtUserDob"
android:textSize="16dp"/>
<TextView
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:id="@+id/txtUserLocation"
android:textSize="16dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<mehdi.sakout.fancybuttons.FancyButton
android:id="@+id/btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp"
android:layout_marginLeft="10dp"
android:onClick="myclick"
fancy:fb_borderColor="#FFFFFF"
fancy:fb_borderWidth="1dp"
fancy:fb_defaultColor="#7ab800"
fancy:fb_focusColor="#9bd823"
fancy:fb_radius="30dp"
fancy:fb_text="Add Profile"
fancy:fb_textColor="#FFFFFF" />
<mehdi.sakout.fancybuttons.FancyButton
android:id="@+id/btn_change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:onClick="myclick"
android:layout_marginLeft="40dp"
fancy:fb_borderColor="#FFFFFF"
fancy:fb_borderWidth="1dp"
fancy:fb_defaultColor="#7ab800"
fancy:fb_focusColor="#9bd823"
fancy:fb_radius="30dp"
fancy:fb_text="Change Profile"
fancy:fb_textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listm0"
android:orientation="vertical"
android:onClick="myclick"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:weightSum="1">
<TextView
android:layout_weight="1"
android:id="@+id/txtPlace"
android:layout_height="match_parent"
android:layout_width="0dp"
android:text="@string/todays_prediction"
android:textSize="16dp"
android:paddingLeft="30dp"
android:gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
<View android:layout_height="1dp"
android:layout_width="match_parent"
android:background="@color/gray_light"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listm1"
android:orientation="vertical"
android:onClick="myclick"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:weightSum="1">
<TextView
android:layout_weight="1"
android:id="@+id/txtPlace"
android:layout_height="match_parent"
android:layout_width="0dp"
android:text="@string/astro_details"
android:textSize="16dp"
android:paddingLeft="30dp"
android:gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listm5"
android:orientation="vertical"
android:onClick="myclick"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:weightSum="1">
<TextView
android:layout_weight="1"
android:id="@+id/txtPlace"
android:layout_height="match_parent"
android:layout_width="0dp"
android:text="@string/yogini"
android:textSize="16dp"
android:paddingLeft="30dp"
android:gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
<View android:layout_height="1dp"
android:layout_width="match_parent"
android:background="@color/gray_light"></View>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
希望它对你有所帮助。干杯!
答案 13 :(得分:0)
根据上述答案,您无法设置速度或灵活地自定义文本视图功能。要拥有自己的滚动速度和灵活性来自定义选取框属性,请使用以下命令:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:lines="1"
android:id="@+id/myTextView"
android:padding="4dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Simple application that shows how to use marquee, with a long text" />
在您的活动中:
private void setTranslation() {
TranslateAnimation tanim = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 1.0f * screenWidth,
TranslateAnimation.ABSOLUTE, -1.0f * screenWidth,
TranslateAnimation.ABSOLUTE, 0.0f,
TranslateAnimation.ABSOLUTE, 0.0f);
tanim.setDuration(1000);//set the duration
tanim.setInterpolator(new LinearInterpolator());
tanim.setRepeatCount(Animation.INFINITE);
tanim.setRepeatMode(Animation.ABSOLUTE);
textView.startAnimation(tanim);
}
答案 14 :(得分:0)
这相当于“结束”:
where = TruncateAt.END
答案 15 :(得分:0)
这是我的xml customTextView对象,您可以在其中使用TextView替换Tag。
<com.wedoapps.crickethisabkitab.utils.view.montserrat.CustomTextView
android:id="@+id/lblRateUsPlayStore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_10sdp"
android:layout_marginBottom="@dimen/_10sdp"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:text="@string/please_rate_us_5_star_on_play_store"
android:textAllCaps="false"
android:textColor="@color/green"
android:textSize="@dimen/_25ssp"
android:textStyle="bold"
android:visibility="visible"
android:linksClickable="true"
android:autoLink="web|phone"/>
这是我的Java文件代码。我已经在服务器上设置了我的html文本,只是替换了textview对象上的文本。如果此textview上的任何链接可以打开移动设备或webBrowser,则我将这段代码放在带有可点击的Marquee标记中。
CustomTextView lblRateUsPlayStore = findViewById(R.id.lblRateUsPlayStore);
lblRateUsPlayStore.setMovementMethod(LinkMovementMethod.getInstance());
lblRateUsPlayStore.setText( Html.fromHtml(documentSnapshot.getString("DisplayText")));
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(lblRateUsPlayStore, 12, 20, 2, 1);
lblRateUsPlayStore.setEllipsize(TextUtils.TruncateAt.MARQUEE);
// Set marquee repeat limit (unlimited)
lblRateUsPlayStore.setMarqueeRepeatLimit(-1);
lblRateUsPlayStore.setHorizontallyScrolling(true);
lblRateUsPlayStore.setSelected(true);
lblRateUsPlayStore.setLinksClickable(true);
lblRateUsPlayStore.setFocusableInTouchMode(true);
lblRateUsPlayStore.setFocusable(true);
答案 16 :(得分:0)
很多答案正确地表明需要呼叫textView.setSelected(true)
。但是,如果更喜欢仅通过 XML 这样做,则一种选择是在与Binding Adapters一起使用时使用Data Binding。
因此,只需创建一个类似于以下内容的新适配器即可:
@BindingAdapter("app:autoStartMarquee")
fun setAutoStartMarquee(textView: TextView, autoStartMarquee: Boolean) {
textView.isSelected = autoStartMarquee
}
然后,您可以简单地在XML中使用它,如下所示:
...
<TextView
...
android:ellipsize="marquee"
android:singleLine="true"
app:autoStartMarquee="@{true}"/>
...
不再需要从代码中调用它。
答案 17 :(得分:0)
您可以使用
android:ellipsize="marquee"
使用您的文本视图。
但是请记住将重点放在所需的文本视图上。
答案 18 :(得分:0)
用于以编程方式设置选取框
TextView textView = (TextView) this.findViewById(R.id.textview_marquee);
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setMarqueeRepeatLimit(-1);
textView.setText("General Information... general information... General Information");
textView.setSelected(true);
textView.setSingleLine(true);