首页
畅所欲言
友情链接
壁纸大全
数据统计
推荐
工具箱
在线白板
Search
1
职教云小助手重构更新,职教云助手最新版下载地址【已和谐】
14,232 阅读
2
职教云-智慧职教,网课观看分析(秒刷网课)
11,468 阅读
3
gradle-5.4.1-all.zip下载
9,507 阅读
4
职教云-智慧职教,签到补签分析(逆天改命系列)
8,203 阅读
5
一个优秀的程序员从写文档开始:免费领14个月语雀云笔记会员
7,018 阅读
学习笔记
Web
Python
转载文章
算法刷题
JS逆向
综合笔记
安卓
物联网
Java
C
资源收集
软件收藏
网络资源
影视专辑
TED英语角
随便写写
随手拍
登录
/
注册
Search
Lan
累计撰写
617
篇文章
累计收到
629
条评论
首页
栏目
学习笔记
Web
Python
转载文章
算法刷题
JS逆向
综合笔记
安卓
物联网
Java
C
资源收集
软件收藏
网络资源
影视专辑
TED英语角
随便写写
随手拍
页面
畅所欲言
友情链接
壁纸大全
数据统计
推荐
工具箱
在线白板
搜索到
452
篇与
的结果
2020-10-09
安卓MPAndroidChart绘制多层级的堆叠条形图
这次是在上一篇的基础上增加的,所以导包这些啥的就跳过了研究了一下代码,发现主要的区别就在于增加data的时候,第二个参数传递的是一个数组,然后就变成了堆叠条形图。最后的代码:XML布局文件:<?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" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="这是一个柱状图" android:gravity="center"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="150dp" android:orientation="vertical"> <com.github.mikephil.charting.charts.BarChart android:id="@+id/barChart" android:layout_width="match_parent" android:layout_height="150dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="这是一个堆叠条形图" android:gravity="center"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="150dp" android:orientation="vertical"> <com.github.mikephil.charting.charts.BarChart android:id="@+id/duiDieChart" android:layout_width="match_parent" android:layout_height="150dp" /> </LinearLayout> </LinearLayout>MainActivity,这里只把堆叠图的代码放出来了,之前的看上一篇文章public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { BarChart duiDieChart = findViewById(R.id.duiDieChart); duiDieChart.getDescription().setEnabled(false); duiDieChart.setMaxVisibleValueCount(40); // 扩展现在只能分别在x轴和y轴 duiDieChart.setPinchZoom(false); duiDieChart.setDrawGridBackground(false); duiDieChart.setDrawBarShadow(false); duiDieChart.setDrawValueAboveBar(false); duiDieChart.setHighlightFullBarEnabled(false); // 改变y标签的位置 YAxis leftAxis = duiDieChart.getAxisLeft(); leftAxis.setDrawGridLines(false); leftAxis.setAxisMinimum(0f); duiDieChart.getAxisRight().setEnabled(false); XAxis xLabels = duiDieChart.getXAxis(); xLabels.setDrawGridLines(true); xLabels.setPosition(XAxis.XAxisPosition.TOP); Legend l = duiDieChart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); l.setFormSize(8f); l.setFormToTextSpace(4f); l.setXEntrySpace(6f); ArrayList<BarEntry> weiZhangZhanBi = new ArrayList<>(); for (int i = 0; i <= 5; i++) { float a = new Random().nextInt(400); float b = new Random().nextInt(400); weiZhangZhanBi.add(new BarEntry(i, new float[]{a, b})); } BarDataSet set1; if (duiDieChart.getData() != null && duiDieChart.getData().getDataSetCount() > 0) { set1 = (BarDataSet) duiDieChart.getData().getDataSetByIndex(0); set1.setValues(weiZhangZhanBi); duiDieChart.getData().notifyDataChanged(); duiDieChart.notifyDataSetChanged(); } else { set1 = new BarDataSet(weiZhangZhanBi, "年龄群体车辆违章的占比统计 "); set1.setColors(getColors()); set1.setStackLabels(new String[]{"有违章", "无违章"}); ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>(); dataSets.add(set1); BarData data = new BarData(dataSets); data.setValueTextColor(Color.WHITE); duiDieChart.setData(data); } duiDieChart.setFitBars(true); duiDieChart.invalidate(); } }看着这篇文章来的:https://blog.csdn.net/qq_26787115/article/details/53323046
2020年10月09日
921 阅读
0 评论
0 点赞
2020-10-09
安卓MPAndroidChart绘制柱状图
首先是添加Jar包进入Gradle Scripts的目录,添加Jar包都在这里首先是Project这个的allprojects里面加上一行allprojects { repositories { google() jcenter() maven { url "https://jitpack.io" } } }在app这个里面denpendencies中弄成这样子的dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' }然后这是xml布局文件<?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" android:orientation="vertical"> <LinearLayout android:id="@+id/chart" android:layout_width="match_parent" android:layout_height="150dp" android:orientation="vertical"> <com.github.mikephil.charting.charts.BarChart android:id="@+id/barChart" android:layout_width="match_parent" android:layout_height="150dp" /> </LinearLayout> </LinearLayout>然后这是Mainactivity的代码package ink.cik.echartsstu; import android.os.Bundle; import android.os.Trace; import androidx.appcompat.app.AppCompatActivity; import com.github.mikephil.charting.charts.BarChart; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.components.Description; import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarEntry; import java.util.ArrayList; import java.util.List; import java.util.Random; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //定义一下界面的控件 BarChart barChart = findViewById(R.id.barChart); initBarChart(barChart); //初始化一个柱状图 barChart.setData(setBarData()); //给柱状图添加数据 barChart.invalidate(); //让柱状图填充数据后刷新 } public BarData setBarData() { List<BarEntry> entries = new ArrayList<>(); //定义一个数据容器 //生成随机数数据 for (int i = 0; i <= 12; i++) { entries.add(new BarEntry(i, new Random().nextInt(300))); } BarDataSet barDataSet = new BarDataSet(entries, "测试数据"); BarData barData = new BarData(barDataSet); return barData; //返回可用于柱状图的数据 } public BarChart initBarChart(BarChart barChart) { barChart.setDrawBarShadow(false); // 设置每条柱子的阴影不显示 barChart.setDrawValueAboveBar(true); // 设置每条柱子的数值显示 XAxis xAxis = barChart.getXAxis(); // 获取柱状图的x轴 YAxis yAxisLeft = barChart.getAxisLeft(); // 获取柱状图左侧的y轴 YAxis yAxisRight = barChart.getAxisRight(); // 获取柱状图右侧的y轴 setAxis(xAxis, yAxisLeft, yAxisRight); //调用方法设置柱状图的轴线 return barChart; } public void setAxis(XAxis xAxis, YAxis leftAxis, YAxis rightAxis) { xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); // 这里设置x轴在柱状图底部显示 xAxis.setAxisLineWidth(1); //设置x轴宽度 xAxis.setAxisMinimum(0); //设置x轴从0开始绘画 xAxis.setDrawAxisLine(true); //设置x轴的轴线显示 xAxis.setDrawGridLines(false);//设置x轴的表格线不显示 xAxis.setEnabled(true); // 设置x轴显示 leftAxis.setAxisMinimum(0); //设置y轴从0刻度开始 leftAxis.setDrawGridLines(false); // 这里设置左侧y轴不显示表格线 leftAxis.setDrawAxisLine(true); // 这里设置左侧y轴显示轴线 leftAxis.setAxisLineWidth(1); //设置y轴宽度 leftAxis.setEnabled(true); //设置左侧的y轴显示 rightAxis.setAxisMinimum(0); //设置y轴从0刻度开始 rightAxis.setDrawGridLines(false);// 这里设置右侧y轴不显示表格线 rightAxis.setDrawAxisLine(true); // 这里设置右侧y轴显示轴线 rightAxis.setAxisLineWidth(1); //设置右侧y轴宽度 rightAxis.setEnabled(true); //设置右侧的y轴显示 } }
2020年10月09日
2,147 阅读
0 评论
0 点赞
2020-10-04
汤圆创作小说检索信息采集
前段时间,因为一些原因,所以需要对这个汤圆创作的小说进行检索,于是写了几行python代码解析了一下搜索出来的结果的信息。# -*- coding: utf-8 -*- """ ------------------------------------------------- @ Author :Lan @ Blog :www.lanol.cn @ Date : 2020/9/30 @ Description:I'm in charge of my Code ------------------------------------------------- """ import requests import parsel for i in range(1, 10094): url = f'https://www.itangyuan.com/search/book/%E4%B8%80%20%E7%94%9F.html?page={i}' res = requests.get(url).text xpathFile = parsel.Selector(res) author = xpathFile.xpath("//p[@class='author']/a/text()").extract() name = xpathFile.xpath("//p[@class='bname']/a/text()").extract() info = xpathFile.xpath("//p[@class='rw_info']/text()").extract() for index, value in enumerate(name): if '一' in value.replace(' ', '') and '生' in value.replace(' ', ''): if int(info[index].split('阅读')[0].replace(' ', '')) < 1000: print(value, author[index], info[index].split('/')[-1]) print(f'已检测至第{i}页')大概就是搜索出所有小说名包含一和生字且阅读量小于1000的。
2020年10月04日
912 阅读
0 评论
0 点赞
2020-09-29
Django设置全局模板变量
最近由于需要,之前做的一个项目需要将图片文件转移至COS对象储存,因为服务器网络不行,图片加载太慢。经过一番猛如虎的操作,目的还是达到了。但是问题来了,图片上传好了,那怎么访问呢,我一开始想的是在数据里加一个表,就是用来存一些默认的字段。但是每次都得去取一次,然后还得返回,感觉实在有点浪费,于是想着有没有全局模板变量,就像我在模板中可以直接调用request.user一样。经过百度,找到了答案。先在一个view中添加你要返回的默认值然后在settings中的Templates->OPTIONS->context_processors进行注册(大概是这样叫吧,个人理解)然后就可以直接在模板中引用这个值了。
2020年09月29日
696 阅读
0 评论
0 点赞
2020-09-26
安卓在子线程传值给主线程,通过Handler传值
昨晚上在进行http请求获取数据并修改listview的时候遇到了一个问题Only the original thread that created a view hierarchy can touch its views大概意思就是:只有创建了视图层级的原始线程才可以修改这个视图于是我百度了一下,然后大概解决方案是这样子的,子线程通过handler传值给主线程,主线程接收后,再进行修改listview。Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what == 1) { Bundle data = msg.getData(); String val = data.getString("value"); //设置UI tvCode.setText(val); Log.i(TAG, "请求结果:" + val); } else if (msg.what ==0) { Toast.makeText(getApplicationContext(),"请求资源不成功",Toast.LENGTH_LONG).show(); } } }; /** * 处理网络请求的线程 */ private class RequestThread extends Thread { @Override public void run() { //网络请求 String string = 请求结果 Message msg = new Message(); Bundle data = new Bundle(); //将获取到的String装载到msg中 data.putString("value", string); msg.setData(data); msg.what = 1; //发消息到主线程 handler.sendMessage(msg); } } //点击事件启动新线程 public void test(View v){ new RequestThread().start(); }解决方法原链接:https://blog.csdn.net/LJX_ahut/article/details/89432576经过实践着实有用。获取前:获取后:MainActivity.java代码package ink.cik.logininfoapp; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import android.annotation.SuppressLint; import android.net.wifi.aware.DiscoverySession; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Adapter; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.Toast; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.util.ArrayList; import java.util.List; import ink.cik.logininfoapp.eneity.userInfo; import ink.cik.logininfoapp.help.httpHelper; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class MainActivity extends AppCompatActivity { private final Gson gson = new Gson(); @SuppressLint("HandlerLeak") Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what == 1) { Bundle data = msg.getData(); String val = data.getString("value"); List<userInfo> userInfoList = parseJson(val); ListView listView = (ListView) findViewById(R.id.listInfo); ArrayList<String> list = new ArrayList<String>();//数据源集合创建 for (userInfo userInfo : userInfoList) { list.add(userInfo.getUserName()); } ArrayAdapter<String> adapter = new ArrayAdapter<String>( MainActivity.this, android.R.layout.simple_list_item_1, list ); listView.setAdapter(adapter); } else if (msg.what == 0) { Toast.makeText(MainActivity.this, "数据获取失败,请检查网络!", Toast.LENGTH_SHORT); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.searchButton); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAll(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu, menu); return true; } private void getAll() { final httpHelper httpHelper = new httpHelper(); new Thread(new Runnable() { @Override public void run() { try { String res = httpHelper.httpGet("https://api.565.ink/login/getAll?passwd=lanol666"); Log.d("结果:", res); Message msg = new Message(); Bundle data = new Bundle(); //将获取到的String装载到msg中 data.putString("value", res); msg.setData(data); msg.what = 1; handler.sendMessage(msg); } catch (Exception e) { e.printStackTrace(); } } }).start(); } private List<userInfo> parseJson(String JsonData) { Gson gson = new Gson(); List<userInfo> userInfoList = gson.fromJson(JsonData, new TypeToken<List<userInfo>>() { }.getType()); return userInfoList; } }
2020年09月26日
1,021 阅读
0 评论
0 点赞
2020-09-24
Android在子线程显示Toast闪退,Can"t toast on a thread that has not called Loop
新建一个类toastHelppackage ink.cik.logininfoapp.eneity; import android.content.Context; import android.os.Looper; import android.widget.Toast; public class toastHelp { static Toast toast = null; public static void show(Context context, String text) { try { if (toast != null) { toast.setText(text); } else { toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); } toast.show(); } catch (Exception e) { //解决在子线程中调用Toast的异常情况处理 Looper.prepare(); Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); Looper.loop(); } } }然后需要用的时候直接调用toastHelp.show(LoginActivity.this, responseInfo.getInfo());
2020年09月24日
1,045 阅读
0 评论
0 点赞
2020-09-24
利用okhttp3调用接口,用gson解析json数据
开心,总算搞好了调用接口获取所有用户信息,然后打印出来了。MainActivity.javapackage ink.cik.logininfoapp; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.IOException; import java.util.List; import java.util.Map; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class MainActivity extends AppCompatActivity { private final Gson gson = new Gson(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.loginButton); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText userName = findViewById(R.id.userName); EditText passWord = findViewById(R.id.passWord); Toast.makeText(MainActivity.this, userName.toString(), Toast.LENGTH_SHORT).show(); verLogin(); } }); } private void verLogin() { new Thread(new Runnable() { @Override public void run() { try { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url("https://api.565.ink/login/getAll?passwd=lanol666").build(); Response response = client.newCall(request).execute(); String responsedata = response.body().string(); Log.d("返回数据:", responsedata); parseJson(responsedata); } catch (IOException e) { e.printStackTrace(); } } }).start(); } private void parseJson(String JsonData) { Gson gson = new Gson(); List<userInfo> userInfoList = gson.fromJson(JsonData, new TypeToken<List<userInfo>>() { }.getType()); for (userInfo userInfo : userInfoList) { Log.d("信息:", userInfo.getUserName()); } } }userInfo.javapackage ink.cik.logininfoapp; public class userInfo { private int id; private String userName; private String passWord; private String nation; private int age; private String tel; public int getAge() { return age; } public String getNation() { return nation; } public int getId() { return id; } public String getPassWord() { return passWord; } public String getTel() { return tel; } public String getUserName() { return userName; } public void setAge(int age) { this.age = age; } public void setId(int id) { this.id = id; } public void setNation(String nation) { this.nation = nation; } public void setPassWord(String passWord) { this.passWord = passWord; } public void setTel(String tel) { this.tel = tel; } public void setUserName(String userName) { this.userName = userName; } }
2020年09月24日
1,102 阅读
0 评论
0 点赞
1
...
28
29
30
...
65