尝试了不同的方法来反转Android中textview的选框。 我用"link"来做这件事。
但它对我不起作用!我的代码有什么问题? 它是我的唯一途径,我不希望动画解决方案导致屏幕限制。
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/a"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/hScroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal" >
<LinearLayout
android:id="@+id/lyr"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="test for reverse marqueee a.test for reverse marqueee b.test for reverse marqueee c." />
</LinearLayout>
</ScrollView>
</LinearLayout>
JAVA:
public class TextmovingActivity extends Activity {
private Integer scroll_pos;
Handler hHandler;
TextView tv;
LinearLayout hsView;
ScrollView hScroll;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.tv);
hScroll = (ScrollView) findViewById(R.id.hScroll);
tv.setSelected(true);
hHandler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
scroll_pos = (int) tv.getLayout().getLineWidth(0);
hScroll.scrollTo(scroll_pos, 0);
scroll_pos--;
if (scroll_pos >= 0)
hHandler.sendEmptyMessage(0);
}
};
}
}
答案 0 :(得分:3)
此解决方案适用于rtl语言(阿拉伯语,波斯语,......):
只需将此属性添加到TextView:
android:textDirection="rtl"
对于17岁以下的API,将此属性添加到TextView:
android:gravity="right"
(它不适用于模拟器,但它与真实手机完美配合。)
<强> Examlpe:强>
XML:
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="write something in Arabic,Persian,... here"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
/>
JAVA:
TextView txt = (TextView) findViewById(R.id.txt);
txt.setSelected(true);