1、list两两分组
/*
* List分割
*/
public static List<List<Map<String, Object>>> groupList(List<Map<String, Object>> list) {
List<List<Map<String, Object>>> listGroup = new ArrayList<List<Map<String, Object>>>();
int listSize = list.size();
//子集合的长度
int toIndex = 2;
for (int i = 0; i < list.size(); i += 2) {
if (i + 2 > listSize) {
toIndex = listSize - i;
}
List<Map<String, Object>> newList = list.subList(i, i + toIndex);
listGroup.add(newList);
}
return listGroup;
}
2、
左右滑动
MPAndroidChart LineChart
float ratio= (float) mLunbo.size() / (float) 30;
//显示的时候是按照多大的比率缩放显示,1f表示不放大缩小
lineChart.zoom(ratio, 1f, 0, 0);
添加点击提示信息:
@SuppressLint("ViewConstructor")
public class HomeMarkerView extends MarkerView {
private final TextView tvContent;
// private final TextView tvContent1;
private final TextView tvContent2;
public HomeMarkerView(Context context, int layoutResource) {
super(context, layoutResource);
tvContent = findViewById(R.id.tvContent);
// tvContent1=findViewById(R.id.tvContent1);
tvContent2=findViewById(R.id.tvContent2);
;
}
// runs every time the MarkerView is redrawn, can be used to update the
// content (user-interface)
@Override
public void refreshContent(Entry e, Highlight highlight) {
Map<String, Object> dates= (Map<String, Object>) e.getData();//自定义提示信息
// tvContent1.setText(dates.get("cdSign").toString());
tvContent2.setText(dates.get("dateStr").toString());
if (e instanceof CandleEntry) {
CandleEntry ce = (CandleEntry) e;
tvContent.setText(dates.get("cdSign").toString()+Utils.formatNumber(ce.getHigh(), 0, true)+"万");
} else {
tvContent.setText(dates.get("cdSign").toString()+Utils.formatNumber(e.getY(), 0, true)+"万");
}
super.refreshContent(e, highlight);
}
@Override
public MPPointF getOffset() {
return new MPPointF(-(getWidth() / 2), -getHeight());
}
}
使用:
HomeMarkerView mv = new HomeMarkerView(getActivity(), R.layout.layout_home_marker_view);//自定义布局
// Set the marker to the chart
mv.setChartView(lineChart);
lineChart.setMarker(mv);
3、监听app是否在前台还是后台(在
MyApplication添加
)
public static int isOpen=1;
private int activityCount;//activity的count数
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityStopped(Activity activity) {
// LogUtil.v(activity + "onActivityStopped");
count--;
if (count == 0) {
isOpen = 0;
Log.d(">>>>>>>>>>>>","切到后台");
// LogUtil.v(">>>>>>>>>>>>>>>>>>>切到后台 lifecycle");
}
isForeground();
}
@Override
public void onActivityStarted(Activity activity) {
// LogUtil.v(activity + "onActivityStarted");
activityCount++;
isOpen = 1;
if (count == 0) {
Log.d(">>>>>>>>>>>>","切到前台");
}
count++;
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// Log.d(activity + "onActivitySaveInstanceState");
Log.d(">>>>>>>>>>>>","onActivitySaveInstanceState");
}
@Override
public void onActivityResumed(Activity activity) {
// LogUtil.v(activity + "onActivityResumed");
Log.d(">>>>>>>>>>>>","onActivityResumed");
isForeground();
}
@Override
public void onActivityPaused(Activity activity) {
// LogUtil.v(activity + "onActivityPaused");
Log.d(">>>>>>>>>>>>","onActivityPaused");
}
@Override
public void onActivityDestroyed(Activity activity) {
// LogUtil.v(activity + "onActivityDestroyed");
}
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
Log.d("activity+ ", "onActivityCreated");
}
});
public static int getIsOpen() {
return isOpen;
}
public static void setIsOpen(int isOpen) {
MyApplication.isOpen = isOpen;
}
使用:
MyApplication.getIsOpen()
5、横竖屏切换:
android:configChanges="screenSize|keyboardHidden|orientation"