关于AndroidChartViews的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于AnOverviewoftheAndroidArchitecture(AndroidStudio)、A
关于Android Chart Views的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于An Overview of the Android Architecture (Android Studio)、Android MPAndroidChart 之 PieChart 和数据结构以及模型【5】、Android SearchView 和 ListView 的结合使用、Android Studio 3.4.1中使用com.android.support.v4.view.ViewPager提示不存在该类或程序闪退等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- Android Chart Views
- An Overview of the Android Architecture (Android Studio)
- Android MPAndroidChart 之 PieChart 和数据结构以及模型【5】
- Android SearchView 和 ListView 的结合使用
- Android Studio 3.4.1中使用com.android.support.v4.view.ViewPager提示不存在该类或程序闪退
Android Chart Views
2021/1/21
1. 饼状图
实现内容:
<1> 动态增加数据
<2> 对于描述位置的冲突,牺牲空间的前提下进行避免
View 地址: https://github.com/meetsl/SAndroidChart/blob/master/app/src/main/java/com/meetsl/sandroidchart/widgets/PieChartView.kt
An Overview of the Android Architecture (Android Studio)
http://www.techotopia.com/index.php/An_Overview_of_the_Android_Architecture_(Android_Studio)
So far in this book, steps have been taken to set up an environment suitable for the development of Android applications using Android Studio. An initial step has also been taken into the process of application development through the creation of a simple Android Studio application project.
Before delving further into the practical matters of Android application development, however, it is important to gain an understanding of some of the more abstract concepts of both the Android SDK and Android development in general. Gaining a clear understanding of these concepts now will provide a sound foundation on which to build further knowledge.Starting with an overview of the Android architecture in this chapter, and continuing in the next few chapters of this book, the goal is to provide a detailed overview of the fundamentals of Android development.
The Android Software Stack
Android is structured in the form of a software stack comprising applications, an operating system, run-time environment, middleware, services and libraries. This architecture can, perhaps, best be represented visually as outlined in Figure 8-1. Each layer of the stack, and the corresponding elements within each layer, are tightly integrated and carefully tuned to provide the optimal application development and execution environment for mobile devices.
Figure 8-1
The remainder of this chapter will work through the different layers of the Android stack, starting at the bottom with the Linux Kernel.
The Linux Kernel
Positioned at the bottom of the Android software stack, the Linux Kernel provides a level of abstraction between the device hardware and the upper layers of the Android software stack. Based on Linux version 2.6, the kernel provides preemptive multitasking, low-level core system services such as memory, process and power management in addition to providing a network stack and device drivers for hardware such as the device display, Wi-Fi and audio.
The original Linux kernel was developed in 1991 by Linus Torvalds and was combined with a set of tools, utilities and compilers developed by Richard Stallman at the Free Software Foundation to create a full operating system referred to as GNU/Linux. Various Linux distributions have been derived from these basic underpinnings such as Ubuntu and Red Hat Enterprise Linux.
It is important to note, however, that Android only uses the Linux kernel. That said, it is worth noting that the Linux kernel was originally developed for use in traditional computers in the form of desktops and servers. In fact, Linux is now most widely deployed in mission critical enterprise server environments. It is a testament to both the power of today’s mobile devices and the efficiency and performance of the Linux kernel that we find this software at the heart of the Android software stack.
Android Runtime - ART
When an Android app is built within Android Studio it is compiled into an intermediate bytecode format (referred to as DEX format). When the application is subsequently loaded onto the device, the Android Runtime (ART) uses a process referred to as Ahead-of-Time (AOT) compilation to translate the bytecode down to the native instructions required by the device processor. This format is known as Executable and Linkable Format (ELF).
Each time the application is subsequently launched, the ELF executable version is run, resulting in faster application performance and improved battery life.
This contrasts with the Just-in-Time (JIT) compilation approach used in older Android implementations whereby the bytecode was translated within a virtual machine (VM) each time the application was launched.
Android Libraries
In addition to a set of standard Java development libraries (providing support for such general purpose tasks as string handling, networking and file manipulation), the Android development environment also includes the Android Libraries. These are a set of Java-based libraries that are specific to Android development. Examples of libraries in this category include the application framework libraries in addition to those that facilitate user interface building, graphics drawing and database access.
A summary of some key core Android libraries available to the Android developer is as follows:- android.app – Provides access to the application model and is the cornerstone of all Android applications.
- android.content – Facilitates content access, publishing and messaging between applications and application components.
- android.database – Used to access data published by content providers and includes SQLite database management classes.
- android.graphics – A low-level 2D graphics drawing API including colors, points, filters, rectangles and canvases.
- android.hardware – Presents an API providing access to hardware such as the accelerometer and light sensor.
- android.opengl – A Java interface to the OpenGL ES 3D graphics rendering API.
- android.os – Provides applications with access to standard operating system services including messages, system services and inter-process communication.
- android.media – Provides classes to enable playback of audio and video.
- android.net – A set of APIs providing access to the network stack. Includes android.net.wifi, which provides access to the device’s wireless stack.
- android.print – Includes a set of classes that enables content to be sent to configured printers from within Android applications.
- android.provider – A set of convenience classes that provide access to standard Android content provider databases such as those maintained by the calendar and contact applications.
- android.text – Used to render and manipulate text on a device display.
- android.util – A set of utility classes for performing tasks such as string and number conversion, XML handling and date and time manipulation.
- android.view – The fundamental building blocks of application user interfaces.
- android.widget - A rich collection of pre-built user interface components such as buttons, labels, list views, layout managers, radio buttons etc.
- android.webkit – A set of classes intended to allow web-browsing capabilities to be built into applications.
Having covered the Java-based libraries in the Android runtime, it is now time to turn our attention to the C/C++ based libraries contained in this layer of the Android software stack.
C/C++ Libraries
The Android runtime core libraries outlined in the preceding section are Java-based and provide the primary APIs for developers writing Android applications. It is important to note, however, that the core libraries do not actually perform much of the actual work and are, in fact, essentially Java “wrappers” around a set of C/C++ based libraries. When making calls, for example, to the android.opengl library to draw 3D graphics on the device display, the library actually ultimately makes calls to the OpenGL ES C++ library which, in turn, works with the underlying Linux kernel to perform the drawing tasks.C/C++ libraries are included to fulfill a wide and diverse range of functions including 2D and 3D graphics drawing, Secure Sockets Layer (SSL) communication, SQLite database management, audio and video playback, bitmap and vector font rendering, display subsystem and graphic layer management and an implementation of the standard C system library (libc).
In practice, the typical Android application developer will access these libraries solely through the Java based Android core library APIs. In the event that direct access to these libraries is needed, this can be achieved using the Android Native Development Kit (NDK), the purpose of which is to call the native methods of non-Java programming languages (such as C and C++) from within Java code using the Java Native Interface (JNI).
Application Framework
The Application Framework is a set of services that collectively form the environment in which Android applications run and are managed. This framework implements the concept that Android applications are constructed from reusable, interchangeable and replaceable components. This concept is taken a step further in that an application is also able to publish its capabilities along with any corresponding data so that they can be found and reused by other applications.
The Android framework includes the following key services:
- Activity Manager – Controls all aspects of the application lifecycle and activity stack.
- Content Providers – Allows applications to publish and share data with other applications.
- Resource Manager – Provides access to non-code embedded resources such as strings, color settings and user interface layouts.
- Notifications Manager – Allows applications to display alerts and notifications to the user.
- View System – An extensible set of views used to create application user interfaces.
- Package Manager – The system by which applications are able to find out information about other applications currently installed on the device.
- Telephony Manager – Provides information to the application about the telelphony services available on the device such as status and subscriber information.
- Location Manager – Provides access to the location services allowing an application to receive updates about location changes.
Applications
Located at the top of the Android software stack are the applications. These comprise both the native applications provided with the particular Android implementation (for example web browser and email applications) and the third party applications installed by the user after purchasing the device.
Summary
A good Android development knowledge foundation requires an understanding of the overall architecture of Android. Android is implemented in the form of a software stack architecture consisting of a Linux kernel, a runtime environment and corresponding libraries, an application framework and a set of applications. Applications are predominantly written in Java and compiled down to bytecode format within the Android Studio build environment. When the application is subsequently installed on a device, this bytecode is compiled down by the Android Runtime (ART) to the native format used by the CPU. The key goals of the Android architecture are performance and efficiency, both in application execution and in the implementation of reuse in application design.
Android MPAndroidChart 之 PieChart 和数据结构以及模型【5】
以 MPAndroidChart 的饼状图 PieChart 为例。
测试的 MainActivity 的 Java 代码:
package com.example.piechart;
import java.util.ArrayList;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.formatter.PercentFormatter;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
/*
* MPAndroidChart比较复杂的部分在于绘制图表的数据源的数据结构。
* 通常,在一个二位的坐标体系内,一个任意的坐标点应包含(x,y)这样的对应数据点。
* 一般模型是在x坐标轴的x-i位置,y存在一个对应的y-i值对应,形成坐标点(i-x,i-y)
* MPAndroidChart在一定角度上将x轴的数据集处理成(i,字符标签)的简单模式,
* 但MPAndroidChart对于y轴的数据集整合成复杂的复合体。初级,y轴的Entry包含(x,y)这样的坐标点数据。
* 比如,在坐标点(xi,yi)的位置绘制数据点,那么在MPAndroidChart中,在x轴的i位置绘制字符串表示是x坐标轴的数值,然后构造y坐标轴的Entry,Entry包含(value,i)
*
* */
public class MainActivity extends Activity {
private PieChart mChart;
private String[] x = new String[] { "A类事物", "B类事物", "C类事物" };
// 凑成100 % 100
private float[] y = { 10f, 60f, 30f };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mChart = (PieChart) findViewById(R.id.chart);
// 图的描述
mChart.setDescription("by Zhang Phil @ http://blog.csdn.net/zhangphil");
// 以3个对应数据集做测试
setData(x.length);
}
private void setData(int count) {
// 准备x"轴"数据:在i的位置,显示x[i]字符串
ArrayList<String> xVals = new ArrayList<String>();
// 真实的饼状图百分比分区。
// Entry包含两个重要数据内容:position和该position的数值。
ArrayList<Entry> yVals = new ArrayList<Entry>();
for (int xi = 0; xi < count; xi++) {
xVals.add(xi, x[xi]);
// y[i]代表在x轴的i位置真实的百分比占
yVals.add(new Entry(y[xi], xi));
}
PieDataSet yDataSet = new PieDataSet(yVals, "百分比占");
// 每个百分比占区块绘制的不同颜色
ArrayList<Integer> colors = new ArrayList<Integer>();
colors.add(Color.RED);
colors.add(Color.GREEN);
colors.add(Color.BLUE);
yDataSet.setColors(colors);
// 将x轴和y轴设置给PieData作为数据源
PieData data = new PieData(xVals, yDataSet);
// 设置成PercentFormatter将追加%号
data.setValueFormatter(new PercentFormatter());
// 文字的颜色
data.setValueTextColor(Color.BLACK);
// 最终将全部完整的数据喂给PieChart
mChart.setData(data);
mChart.invalidate();
}
}
需要的布局文件,其实就一个 PieChart 元素:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.piechart.MainActivity" >
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
代码运行结果:
相关文章:
【1】《Android 统计图表 MPAndroidChart》链接地址:http://blog.csdn.net/zhangphil/article/details/47656521
【2】《基于 Android MPAndroidChart 实现腾讯 QQ 群数据统计报表核心功能》链接地址:http://blog.csdn.net/zhangphil/article/details/47685515
【3】《Android 实现天气预报温度 / 气温折线趋势图》链接地址:http://blog.csdn.net/zhangphil/article/details/47702245
【4】《Android 统计图表之柱状图(条形图)》链接地址:http://blog.csdn.net/zhangphil/article/details/47727913
【5】MPAndroidChart 在 github 上的项目主页:https://github.com/PhilJay/MPAndroidChart
Android SearchView 和 ListView 的结合使用
今天学习了 Android 里面的搜索框 SearchView 的知识,刚开始也是在网上找找有没有大神写的小例子来参考。后来找了一篇跟我标题一样的文章,我把代码自己敲了一遍,后面在模拟器上面运行的时候一直提示:应用程序终止。看了下导致这个情况的地方是因为里面对 SearchView 使用了 setOnQueryChangeListener 监听,会出现问题。具体什么问题我也不是很清楚,小弟最近才开始学习。
但是作为监听器本身应该是不会有问题,这毕竟是早就写好给我们使用的工具,我想应该是里面执行代码的问题。他们用的是 TextUtils.isEmpty (String text) 来对搜索框里面用户输入的内容进行判断,然后再去设置 ListView 对象内容的变动。TextUtils 我不了解,但是我觉得应该是它的问题,果断的删了,然后自己用了比较简单的判断来写。
代码如下:
activity_main.xml 文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<SearchView
android:id="@+id/srv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:iconifiedByDefault="false"
android:inputType="textFilter"
android:queryHint="请输入您要查找的内容"/>
<ListView
android:id="@+id/lv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#969696"/>
</LinearLayout>
activity 的 java 代码:
package com.example.searchview_test;
import java.util.ArrayList;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.text.Layout;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.Toast;
@SuppressLint("NewApi")
public class MainActivity extends Activity {
private SearchView srv1;
private ListView lv1;
private ArrayAdapter<String> aadapter;
private String[] names;
private ArrayList<String> alist;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
srv1=(SearchView)findViewById(R.id.srv1);
names=new String[]{"ad","dffa","uyiu","rqer","qwgt","afrgb","rtyr"};
lv1=(ListView)findViewById(R.id.lv1);
aadapter=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_expandable_list_item_1, names);
lv1.setAdapter(aadapter);
lv1.setTextFilterEnabled(true);
srv1.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// TODO Auto-generated method stub
// Toast.makeText(MainActivity.this, "1111", Toast.LENGTH_LONG).show();
if(newText.length()!=0){
lv1.setFilterText(newText);
}else{
lv1.clearTextFilter();
}
return false;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Android Studio 3.4.1中使用com.android.support.v4.view.ViewPager提示不存在该类或程序闪退
本文链接:https://blog.csdn.net/Marco_L/article/details/95097518
在编写这段代码的时候你会发现输入时并没有任何关于类的选择提示,但是全部打完后编译可以通过(细心的话回发现在右侧proview中会有错误提示,如下)。
但是!!!!程序运行后会闪退
从网上搜了很多资料,大部分都是针对eclipse的,并且少数关于Android Studio的根本没有效果。后来无意间看到Android Studio在新的版本中对android.support中的内容进行了更新。
com.android.support.v4.view.ViewPager
变成了
androidx.viewpager.widget.ViewPager 程序可以正常运行。
其他变动请参照:
https://blog.csdn.net/yin_ol/article/details/89421390
如有其他未列出的依赖,请参考 https://developer.android.google.cn/topic/libraries/support-library/refactor
关于Android Chart Views的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于An Overview of the Android Architecture (Android Studio)、Android MPAndroidChart 之 PieChart 和数据结构以及模型【5】、Android SearchView 和 ListView 的结合使用、Android Studio 3.4.1中使用com.android.support.v4.view.ViewPager提示不存在该类或程序闪退等相关内容,可以在本站寻找。
本文标签: