diff --git a/app/src/main/java/com/stx/xmarqueeviewdemo/MainActivity.java b/app/src/main/java/com/stx/xmarqueeviewdemo/MainActivity.java index ffa040e..f2c3f99 100644 --- a/app/src/main/java/com/stx/xmarqueeviewdemo/MainActivity.java +++ b/app/src/main/java/com/stx/xmarqueeviewdemo/MainActivity.java @@ -2,6 +2,8 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; import com.stx.xmarqueeview.XMarqueeView; @@ -11,6 +13,7 @@ public class MainActivity extends AppCompatActivity { private List mDatas; + private MarqueeViewAdapter mMarqueeViewAdapter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -35,10 +38,21 @@ private void initView() { XMarqueeView xMarqueeView = (XMarqueeView) findViewById(R.id.marquee3); - xMarqueeView.setAdapter(new MarqueeViewAdapter(mDatas, this)); - - //刷新数据 -// marqueeViewAdapter.setData(mDatas); + mMarqueeViewAdapter = new MarqueeViewAdapter(mDatas, this); + xMarqueeView.setAdapter(mMarqueeViewAdapter); + Button btn = (Button) findViewById(R.id.btn); + + btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mDatas.clear(); + for (int i = 0; i < 4; i++) { + mDatas.add("这是刷新后的跑马灯内容" + (i + 1)); + } + //刷新数据 + mMarqueeViewAdapter.setData(mDatas); + } + }); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ff17fab..ceea1b6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,11 +1,11 @@ + 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" + tools:context="com.stx.xmarqueeviewdemo.MainActivity"> + android:src="@drawable/icon_order_success"/> + app:isSingleLine="true"/> + android:src="@drawable/icon_report_btn"/> @@ -48,7 +48,7 @@ android:layout_height="wrap_content" android:layout_margin="12dp" android:scaleType="fitXY" - android:src="@drawable/icon_order_success" /> + android:src="@drawable/icon_order_success"/> + app:marquee_count="2"/> + android:src="@drawable/icon_report_btn"/> @@ -78,7 +78,7 @@ android:layout_height="wrap_content" android:layout_margin="12dp" android:scaleType="fitXY" - android:src="@drawable/icon_order_success" /> + android:src="@drawable/icon_order_success"/> + app:marquee_count="3"/> + android:src="@drawable/icon_report_btn"/> + +