Skip to content

Commit

Permalink
优化demo
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohaibin committed Aug 1, 2019
1 parent e3aaa10 commit be28702
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
22 changes: 18 additions & 4 deletions app/src/main/java/com/stx/xmarqueeviewdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -11,6 +13,7 @@
public class MainActivity extends AppCompatActivity {

private List<String> mDatas;
private MarqueeViewAdapter mMarqueeViewAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -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);
}
});
}

}
37 changes: 22 additions & 15 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?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"
tools:context="com.stx.xmarqueeviewdemo.MainActivity">
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">

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -17,22 +17,22 @@
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:scaleType="fitXY"
android:src="@drawable/icon_order_success" />
android:src="@drawable/icon_order_success"/>

<com.stx.xmarqueeview.XMarqueeView
android:id="@+id/marquee1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:isSetAnimDuration="true"
app:isSingleLine="true" />
app:isSingleLine="true"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:scaleType="fitXY"
android:src="@drawable/icon_report_btn" />
android:src="@drawable/icon_report_btn"/>

</LinearLayout>

Expand All @@ -48,22 +48,22 @@
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:scaleType="fitXY"
android:src="@drawable/icon_order_success" />
android:src="@drawable/icon_order_success"/>

<com.stx.xmarqueeview.XMarqueeView
android:id="@+id/marquee2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:isSetAnimDuration="true"
app:marquee_count="2" />
app:marquee_count="2"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:scaleType="fitXY"
android:src="@drawable/icon_report_btn" />
android:src="@drawable/icon_report_btn"/>

</LinearLayout>

Expand All @@ -78,23 +78,30 @@
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:scaleType="fitXY"
android:src="@drawable/icon_order_success" />
android:src="@drawable/icon_order_success"/>

<com.stx.xmarqueeview.XMarqueeView
android:id="@+id/marquee3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:isSetAnimDuration="true"
app:marquee_count="3" />
app:marquee_count="3"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:scaleType="fitXY"
android:src="@drawable/icon_report_btn" />
android:src="@drawable/icon_report_btn"/>

</LinearLayout>


<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="刷新数据"/>

</LinearLayout>

0 comments on commit be28702

Please sign in to comment.