谁知道墨迹天气里面的“气温走势图”用的是什么API,知道的说一下,急需这样漂亮的走势图

fight_to_win_1980 2013-04-10 04:10:23

上图为墨迹天气效果图,这种效果怎么做啊
懂得说一下
...全文
394 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
DrSmart 2014-03-05
  • 打赏
  • 举报
回复
描点画图,不难的楼主,上面回复的不错
wlcw16 2013-04-10
  • 打赏
  • 举报
回复
MainActivity

package com.example.zdemo;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class MainActivity extends Activity {

private RelativeLayout rl ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<Integer> high = new ArrayList<Integer>();
high.add(40);
high.add(35);
high.add(50);
high.add(45);
List<Integer> low = new ArrayList<Integer>();
low.add(-10);
low.add(5);
low.add(0);
low.add(-20);
MyChartView chart = new MyChartView(MainActivity.this , high , low);
rl = (RelativeLayout)findViewById(R.id.rl);
LayoutParams lp = new RelativeLayout.LayoutParams(400,200);
chart.setLayoutParams(lp);
rl.addView(chart);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}



MyChartView

package com.example.zdemo;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

public class MyChartView extends View {

private List< Integer> highTemprature = new ArrayList<Integer>();

private List< Integer> lowTemprature = new ArrayList<Integer>();

private boolean isDataEnough = false;

public MyChartView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

}

public MyChartView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public MyChartView(Context context) {
this(context, null);
}

public MyChartView(Context context, List<Integer> a,
List< Integer> b) {
this(context);
highTemprature = a;
lowTemprature = b;
init();
}

private void init() {
if(highTemprature.size() < 4 || lowTemprature.size() < 4){
isDataEnough = false;
}
else{
isDataEnough = true;
if (highTemprature.size() > 4) {
highTemprature = highTemprature.subList(0, 4);
}
if (lowTemprature.size() > 4) {
lowTemprature = lowTemprature.subList(0, 4);
}
}
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paintGRAY = new Paint();
Paint paintWHITE = new Paint();
Paint paintBLUE = new Paint();
Paint paintRED = new Paint();
paintGRAY.setColor(Color.GRAY);
paintWHITE.setColor(Color.WHITE);
paintBLUE.setColor(Color.BLUE);
paintRED.setColor(Color.RED);
canvas.drawRect(new Rect(0, 0, getWidth(), getHeight()), paintGRAY);
if(isDataEnough){
float singleWidth = getWidth()/4;
float lastX = 0;
float lastY = 0;
float curX = 0;
float curY = 0;
//画高温线
for(int i = 0 ; i < 4 ; i++){
//画点
canvas.drawCircle(singleWidth/2+i*singleWidth, getHeight()/2-highTemprature.get(i), 5, paintWHITE);
if(i == 0){
lastX = singleWidth/2+i*singleWidth;
lastY = getHeight()/2-highTemprature.get(i);
}
//画线
else{
curX = singleWidth/2+i*singleWidth;
curY = getHeight()/2-highTemprature.get(i);
canvas.drawLine(lastX, lastY, curX, curY, paintRED);
lastX = curX;
lastY = curY;
}
}
//低温线
for(int i = 0 ; i < 4 ; i++){
//画点
canvas.drawCircle(singleWidth/2+i*singleWidth, getHeight()/2-lowTemprature.get(i), 5, paintWHITE);
if(i == 0){
lastX = singleWidth/2+i*singleWidth;
lastY = getHeight()/2-lowTemprature.get(i);
}
//画线
else{
curX = singleWidth/2+i*singleWidth;
curY = getHeight()/2-lowTemprature.get(i);
canvas.drawLine(lastX, lastY, curX, curY, paintBLUE);
lastX = curX;
lastY = curY;
}
}
}
}
}



activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent" >

</RelativeLayout>



给分吧。
wlcw16 2013-04-10
  • 打赏
  • 举报
回复
这应该是他自己定义的控件把。 重写了onDraw方法 构造方法是两个list为参数(高低温数据) 大概就是这种思路,通过数据画出整个view
fight_to_win_1980 2013-04-10
  • 打赏
  • 举报
回复
大家救救这个帖子吧
fight_to_win_1980 2013-04-10
  • 打赏
  • 举报
回复
就这么的沉了啊
fight_to_win_1980 2013-04-10
  • 打赏
  • 举报
回复
没有人知道么?? 知道的说说吧 ,怎么实现的

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧