public class Crunk extends Activity {
TextView textView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crunk);
Button button = null;
button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.e("It's Clicked", "Don't Worry");
textView.setText("SeeMe");
textView.setEllipsize(TruncateAt.MARQUEE);
}
});
textView = (TextView)this.findViewById(R.id.textView1);
textView.setSelected(true);
textView.setText("Waitin'....");
}
此代码仅显示文本而非选取框效果。
帮我解决问题。
我希望文本在点击按钮时显示效果。
即使尝试了大部分事情,仍然无法获得理想的效果....
<RelativeLayout 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" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="180dp"
android:text="@string/TapMe" />
<TextView
android:text="@string/SeeMe"
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="51dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
答案 0 :(得分:1)
您可以在layout.xml中设置这些属性
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
答案 1 :(得分:1)
设置所有需要的三件事(ellipsize, selected, and singleLine
):
TextView tv = (TextView)findViewById(R.id.someTextView);
tv.setSelected(true);
tv.setText("Simple application that shows how to use marquee, with a long ");
tv.setEllipsize(TruncateAt.MARQUEE);
tv.setSingleLine(true):
答案 2 :(得分:0)
您的TextView
R.id.textView1
是否拥有此属性?
机器人:SINGLELINE = “真”
答案 3 :(得分:0)
添加到textview xml属性......
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
答案 4 :(得分:0)
在按钮的onClick()
中尝试以下代码:
button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.e("It's Clicked", "Don't Worry");
textView.setText("Simple application that shows how to use marquee, with a long ");
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setSelected(true);
textView.setSingleLine(true);
}
});
您在textView.setText("SeeMe");
中设置的是小文本,然后是textView's
宽度。