4

1つのボタンをクリックしてマーキーテキストを左右に移動する方法、これを行うにはどうすればよいですか?

4

4 に答える 4

7

これを試して;

Animation animationToLeft = new TranslateAnimation(400, -400, 0, 0);
animationToLeft.setDuration(12000); 
animationToLeft.setRepeatMode(Animation.RESTART);
animationToLeft.setRepeatCount(Animation.INFINITE);

Animation animationToRight = new TranslateAnimation(-400,400, 0, 0);
animationToRight.setDuration(12000); 
animationToRight.setRepeatMode(Animation.RESTART);
animationToRight.setRepeatCount(Animation.INFINITE);

TextView textViewMarqToLeft = (TextView) findViewById(R.id.textViewMarqToLeft);
TextView textViewMarqToRight = (TextView) findViewById(R.id.textViewMarqToRight);

textViewMarqToLeft.setAnimation(animationToLeft);
textViewMarqToRight.setAnimation(animationToRight);
String textLeft = "Left marquue"
String textRight = "Right marquue"
textViewMarqToLeft.setText(textLeft);
textViewMarqToRight.setText(textRight);
于 2012-09-04T10:37:31.893 に答える
2

例はこちら

<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:lines="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" />

それをアクティビティボタンに呼び出します

tv = (TextView) this.findViewById(R.id.tv);  
tv.setSelected(true); 
于 2012-07-16T12:05:52.893 に答える
0

これをチェックしてください:

<ScrollView
        android:id="@+id/sc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/mark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/btn"
            android:layout_below="@+id/txt"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="Thanks Christian but I am trying to get my text to scroll downwards automatically I am able to scroll horizontally fine."
            android:textSize="50dp" />
    </ScrollView>

<Button
android:id="@+id/button"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
android:text="Scroll"/>

アクティビティで次のように記述します。

ScrollView scrollView=(ScrollView) findViewById(R.id.sc);
Button button=(Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            scrollView.post(new Runnable() {

        public void run() {
            scrollView.smoothScrollTo(0, scrollView.getBottom());
        }
    });
        }
    });
于 2012-07-16T12:05:15.560 に答える