我想用安卓来证明我的TextSwitcher是合理的。但我找不到任何解决办法。我增加了一个TextSwitcher,如下所示
<TextSwitcher
android:id="@+id/ts_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/left_offset"/>但文字没有左对齐和右对齐,如下图-
斯塔克斯统治了北方,直到罗布·斯塔克在罗斯·博尔顿的红色婚礼上背叛了他。从那以后,是博尔顿统治了北方,他们的座位从德雷德堡转移到了临冬城。卡斯塔克、曼德利、翁伯、里德和莫蒙特是宣誓效忠北方典狱长的主要附庸。
我想要使这些文字左对右对齐。
发布于 2018-06-08 13:42:57
创建一个ViewFactory并重写makeView函数,以便为文本切换程序使用您自己的自定义视图/文本视图。您应该能够在该视图上设置属性。
TextSwitcher exampleTextSwitcher;
exampleTextSwitcher.setFactory(textSwitcherFactory);
private ViewSwitcher.ViewFactory textSwitcherFactory = new ViewSwitcher.ViewFactory()
{
@Override
public View makeView()
{
LayoutInflater inflater = LayoutInflater.from(context);
return inflater.inflate(R.layout.view_timer_textview, null);
}
};view_timer_textview.xml
<TextView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/test"
android:includeFontPadding="true"
android:textAlignment="center"
android:layout_gravity="center"
android:lines="1"
android:ellipsize="end"/>发布于 2020-05-13 12:36:25
您还可以通过代码直接完成此操作,例如:
TextSwitcher textSwitcher = findViewById(R.id.your_id_text_switcher);
textSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
tvSwitcher = new TextView(MainActivity.this);
tvSwitcher.setTextColor(getResources().getColor(R.color.textColor));
tvSwitcher.setTextSize(18);
//edit lines as follows
tvSwitcher.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
return tvSwitcher;
}
});https://stackoverflow.com/questions/50757017
复制相似问题