生活随笔
收集整理的這篇文章主要介紹了
详情页面,折线图
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
詳情頁面
public class CommodityActivity extends AppCompatActivity implements MainView, View.OnClickListener {
private ViewPager mImage;
private TextView mPrice, mNum, mTitle;
private ImagePageAdapter mImagePageAdapter;
//折線圖
private EditText xedit, yedit;
private LineView lineView;@Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_commodity_deails);//初始化findViewById(R.id.add_btn).setOnClickListener(this);xedit = findViewById(R.id.x_edit);yedit = findViewById(R.id.y_edit);lineView = findViewById(R.id.lineView);int id = getIntent().getIntExtra("id", 103);MainPresenterIml mainPresenterIml = new MainPresenterIml(new MainModelIml(), this);mainPresenterIml.doShopDetail(id + "");mImage = (ViewPager) findViewById(R.id.viewpage);mPrice = (TextView) findViewById(R.id.tv_price);mNum = (TextView) findViewById(R.id.tv_num);mTitle = (TextView) findViewById(R.id.tv_title);mImagePageAdapter = new ImagePageAdapter();mImage.setAdapter(mImagePageAdapter);
}private String[] picTrueArr;@Override
public void success(String json) {try {ShopDatailBean bean = new Gson().fromJson(json, ShopDatailBean.class);mTitle.setText(bean.getResult().getCommodityName());mPrice.setText("¥" + bean.getResult().getPrice());mNum.setText("已售" + bean.getResult().getSaleNum() + "件");String picTrue = bean.getResult().getPicture();picTrueArr = picTrue.split(",");mImagePageAdapter.notifyDataSetChanged();//Glide.with(this).load(bean.getResult().getPicture())} catch (Exception e) {e.printStackTrace();}
}@Override
public void fail() {}//折線圖
@Override
public void onClick(View v) {int x = Integer.parseInt(xedit.getText().toString());int y = Integer.parseInt(yedit.getText().toString());lineView.addView(x, y);
}private class ImagePageAdapter extends PagerAdapter {@Overridepublic int getCount() {if (picTrueArr == null) {return 0;}return picTrueArr.length;}@Overridepublic boolean isViewFromObject(@NonNull View view, @NonNull Object o) {return view == o;}@NonNull@Overridepublic Object instantiateItem(@NonNull ViewGroup container, int position) {ImageView imageView = new ImageView(CommodityActivity.this);Glide.with(CommodityActivity.this).load(picTrueArr[position]).into(imageView);container.addView(imageView);return imageView;}@Overridepublic void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {// super.destroyItem(container, position, object);container.removeView((View) object);}
}
}
折線圖
public class LineView extends View {
final static int TEXTSIZE=20;
final static int STARTX=50;
final static int STARTY=600;
private Paint mypaint;
private Path path;public LineView(Context context) {super(context);
}public LineView(Context context, AttributeSet attrs) {super(context, attrs);init();
}public LineView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init();
}private void init() {mypaint = new Paint();mypaint.setColor(Color.RED);mypaint.setStyle(Paint.Style.STROKE);mypaint.setTextSize(TEXTSIZE);mypaint.setStrokeWidth(1);path = new Path();path.moveTo(STARTX,STARTY);
}@Override
protected void onDraw(Canvas canvas) {super.onDraw(canvas);canvas.drawPath(path,mypaint);canvas.drawLine(STARTX,STARTY,STARTX+400,STARTY,mypaint);canvas.drawLine(STARTX,STARTY,STARTX,STARTY-400,mypaint);canvas.drawText("0",STARTX-20,STARTY+10,mypaint);for (int i = 50; i <=400 ; i+=50) {String str=i+"";
// float v = mypaint.measureText(str);
canvas.drawText(str,STARTX-40,STARTY-i,mypaint);
canvas.drawText(str,STARTX+i,STARTY+40,mypaint);
}
}
public void addView(int x,int y){
path.lineTo(STARTX+x,STARTY-y);
invalidate();
}
}
總結(jié)
以上是生活随笔為你收集整理的详情页面,折线图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。