indicator
This commit is contained in:
@@ -47,6 +47,6 @@ dependencies {
|
||||
//MP Chart
|
||||
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
|
||||
|
||||
//slipe
|
||||
implementation 'com.github.chenupt.android:springindicator:1.0.2@aar'
|
||||
//indicator
|
||||
implementation 'com.ryanjeffreybrooks:indefinitepagerindicator:1.0.10'
|
||||
}
|
||||
|
||||
@@ -2,24 +2,19 @@ package com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.mikephil.charting.charts.PieChart;
|
||||
import com.github.mikephil.charting.components.Description;
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
import com.github.mikephil.charting.data.PieData;
|
||||
import com.github.mikephil.charting.data.PieDataSet;
|
||||
import com.github.mikephil.charting.data.PieEntry;
|
||||
import com.github.mikephil.charting.formatter.PercentFormatter;
|
||||
import com.rbrooks.indefinitepagerindicator.IndefinitePagerIndicator;
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
@@ -34,9 +29,12 @@ public class SleepFragment extends BaseFragment {
|
||||
WaveLoadingView waveLoadingView;
|
||||
@BindView(R.id.sleep_text)
|
||||
TextView sleepText;
|
||||
@BindView(R.id.sleep_pie)
|
||||
PieChart sleepPie;
|
||||
|
||||
Unbinder unbinder;
|
||||
@BindView(R.id.viewpager_pager_indicator)
|
||||
IndefinitePagerIndicator viewpagerPagerIndicator;
|
||||
@BindView(R.id.view_pager)
|
||||
ViewPager viewPager;
|
||||
|
||||
@Override
|
||||
protected Handler initHandle() {
|
||||
@@ -55,9 +53,11 @@ public class SleepFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
initPie();
|
||||
// initPie();
|
||||
initViewPager();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// TODO: inflate a fragment view
|
||||
@@ -75,35 +75,55 @@ public class SleepFragment extends BaseFragment {
|
||||
/**
|
||||
* 绘制饼图
|
||||
*/
|
||||
private void initPie() {
|
||||
List<PieEntry> strings = new ArrayList<>();
|
||||
strings.add(new PieEntry(30f, "深度睡眠"));
|
||||
strings.add(new PieEntry(70f, "浅度睡眠"));
|
||||
|
||||
PieDataSet dataSet = new PieDataSet(strings, "");
|
||||
|
||||
ArrayList<Integer> colors = new ArrayList<Integer>();
|
||||
colors.add(getResources().getColor(R.color.sleep_deep));
|
||||
colors.add(getResources().getColor(R.color.sleep_shallow));
|
||||
dataSet.setColors(colors);
|
||||
dataSet.setValueTextSize(16f);
|
||||
PieData pieData = new PieData(dataSet);
|
||||
pieData.setDrawValues(true);
|
||||
pieData.setValueFormatter(new PercentFormatter());
|
||||
pieData.setValueTextSize(16f);
|
||||
pieData.setValueTextColor(getResources().getColor(R.color.place_holder));
|
||||
// private void initPie() {
|
||||
// List<PieEntry> strings = new ArrayList<>();
|
||||
// strings.add(new PieEntry(30f, "深度睡眠"));
|
||||
// strings.add(new PieEntry(70f, "浅度睡眠"));
|
||||
//
|
||||
// PieDataSet dataSet = new PieDataSet(strings, "");
|
||||
//
|
||||
// ArrayList<Integer> colors = new ArrayList<Integer>();
|
||||
// colors.add(getResources().getColor(R.color.sleep_deep));
|
||||
// colors.add(getResources().getColor(R.color.sleep_shallow));
|
||||
// dataSet.setColors(colors);
|
||||
// dataSet.setValueTextSize(16f);
|
||||
// PieData pieData = new PieData(dataSet);
|
||||
// pieData.setDrawValues(true);
|
||||
// pieData.setValueFormatter(new PercentFormatter());
|
||||
// pieData.setValueTextSize(16f);
|
||||
// pieData.setValueTextColor(getResources().getColor(R.color.place_holder));
|
||||
//
|
||||
//
|
||||
// sleepPie.setData(pieData);
|
||||
// sleepPie.invalidate();
|
||||
//
|
||||
// Description description = new Description();
|
||||
// description.setText("");
|
||||
// sleepPie.setDescription(description);
|
||||
// sleepPie.setHoleRadius(0f);
|
||||
// sleepPie.setTransparentCircleRadius(0f);
|
||||
// Legend legend = sleepPie.getLegend();
|
||||
// legend.setEnabled(false);
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
sleepPie.setData(pieData);
|
||||
sleepPie.invalidate();
|
||||
|
||||
Description description = new Description();
|
||||
description.setText("");
|
||||
sleepPie.setDescription(description);
|
||||
sleepPie.setHoleRadius(0f);
|
||||
sleepPie.setTransparentCircleRadius(0f);
|
||||
Legend legend = sleepPie.getLegend();
|
||||
legend.setEnabled(false);
|
||||
/**
|
||||
* 初始化Viewpager
|
||||
*/
|
||||
private void initViewPager() {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
viewPager.setAdapter(new FragmentPagerAdapter(fragmentManager) {
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
return new SleepViewPagerItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 10;
|
||||
}
|
||||
});
|
||||
viewpagerPagerIndicator.attachToViewPager(viewPager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt;
|
||||
|
||||
import android.os.Handler;
|
||||
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/8/20.
|
||||
*/
|
||||
|
||||
public class SleepViewPagerItem extends BaseFragment {
|
||||
@Override
|
||||
protected Handler initHandle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_sleep_item;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshData() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -88,15 +88,27 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1.2"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.github.mikephil.charting.charts.PieChart
|
||||
android:id="@+id/sleep_pie"
|
||||
<com.rbrooks.indefinitepagerindicator.IndefinitePagerIndicator
|
||||
android:id="@+id/viewpager_pager_indicator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="5dp"
|
||||
app:dotColor="#a1a8da"
|
||||
app:dotCount="3"
|
||||
app:dotRadius="8dp"
|
||||
app:dotSeparation="16dp"
|
||||
app:selectedDotColor="#3d4ec9"
|
||||
app:selectedDotRadius="6dp" />
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/view_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</com.github.mikephil.charting.charts.PieChart>
|
||||
</android.support.v4.view.ViewPager>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="test" />
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user