compile 'com.robinhood.ticker:ticker:1.0.0'
activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TickerView"
android:textSize="30sp" />
<com.robinhood.ticker.TickerView
android:id="@+id/tickerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp" />
<Button
android:id="@+id/btnClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Click" />
<Button
android:id="@+id/btnThread"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Start Thread" />
</LinearLayout>
MainActivity
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
String TAG = "MainActivity";
int a = 0;
private TickerView ticker1;
private Button btnClick;
private Button btnThread;
private static final char[] NUMBER_LIST = TickerUtils.getDefaultNumberList();
private Handler handler;
boolean flag = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
handler = new Handler();
btnClick = (Button) findViewById(R.id.btnClick);
btnThread = (Button) findViewById(R.id.btnThread);
btnClick.setOnClickListener(this);
btnThread.setOnClickListener(this);
ticker1 = (TickerView) findViewById(R.id.tickerView);
ticker1.setCharacterList(NUMBER_LIST);
ticker1.setAnimationDuration(500);
ticker1.setTextColor(Color.parseColor("#FF0000"));
ticker1.setTextSize(100);
ticker1.setAnimationDuration(500);
ticker1.setAnimationInterpolator(new OvershootInterpolator());
}
Runnable runnable = new Runnable() {
@Override
public void run() {
handler.postDelayed(runnable, 200);
if (!flag) {
a++;
ticker1.setText("" + a);
}
}
};
@Override
protected void onPause() {
super.onPause();
flag = true;
}
@Override
public void onClick(View v) {
if (v == btnClick) {
a++;
ticker1.setText("" + a);
} else if (v == btnThread) {
handler.post(runnable);
}
}
}
No comments:
Post a Comment