如何使用View自定义属性画圆

//主方法
package com.example.tianjiale20160808;

import view.LegePaint;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	private EditText ed2;
	private EditText ed3;
	private EditText ed4;
	private Button but5;
	private LegePaint mlege;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		findid();

	}

	private void findid() {
		ed2 = (EditText) findViewById(R.id.ed2);
		ed3 = (EditText) findViewById(R.id.ed3);
		ed4 = (EditText) findViewById(R.id.ed4);
		but5 = (Button) findViewById(R.id.but5);
		mlege = (LegePaint) findViewById(R.id.mlegeView);
		Log.i("lege", "aaaaaaaaaaaaaaaaaaaaaaaa");

		but5.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String trim1 = ed2.getText().toString().trim();
				String trim2 = ed3.getText().toString().trim();
				String trim3 = ed4.getText().toString().trim();
				if (trim1.length() >= 1 && trim1.length() >= 1
						&& trim1.length() >= 1) {
					//强转String型为Float型       参数不能为空
					float price1 = Float.parseFloat(trim1);
					float price2 = Float.parseFloat(trim2);
					Log.i("lege", price1 + "");
					Log.i("lege", price2 + "");
					Log.i("lege", trim3);
					//通过有参构造 赋值
					mlege.setP1(price1);
					mlege.setP2(price2);
					mlege.setTrim(trim3);
					//从新绘制
					mlege.invalidate();
				} else {
					Toast.makeText(MainActivity.this, "最后一个参数格式是   #FF0000", 0).show();
				}
			}
		});
	}

}

//集成view类
package view;

import com.example.tianjiale20160808.MainActivity;

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

public class LegePaint extends View {
    private Context context;
    private float p1=10;
    private float p2=5;
    private String trim="#ffffff";
    private Paint mpaint;
    

    public float getP1() {
        return p1;
    }

    public void setP1(float p1) {
        this.p1 = p1;
    }

    public float getP2() {
        return p2;
    }

    public void setP2(float p2) {
        this.p2 = p2;
    }

    public String getTrim() {
        return trim;
    }

    public void setTrim(String trim) {
        this.trim = trim;
    }



    public LegePaint(Context context) {
        this(context,null);
    }
    public LegePaint(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }
    public LegePaint(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mpaint =new Paint(Paint.ANTI_ALIAS_FLAG);
        mpaint.setStyle(Paint.Style.STROKE);
        
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mpaint.setStrokeWidth(p2);
        mpaint.setColor(Color.parseColor(trim));
        Log.i("le", p1+"aaaaaaaaaaaaa"+p2+"trim");
        canvas.drawCircle(300, 300, p1, mpaint);
    }
    public void shuxin(){
        invalidate();
    }
}


//布局文件

<LinearLayout 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"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
    <LinearLayout 
        android:id="@+id/bu1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#00FF00">
        <TextView
        android:id="@+id/title1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="自定义圆环" 
        android:layout_marginLeft="120dp"
        android:layout_marginTop="20dp"
        />
    </LinearLayout>
    <LinearLayout 
        android:id="@+id/bu2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
       >
        <TextView
        android:id="@+id/title2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="圆的半径" 
        />
        <EditText 
            android:id="@+id/ed2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="9"/>
    </LinearLayout>
    <LinearLayout 
        android:id="@+id/bu3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
       >
        <TextView
        android:id="@+id/title3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="圆环的宽度" 
        />
        <EditText 
            android:id="@+id/ed3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="9"/>
    </LinearLayout>
    <LinearLayout 
        android:id="@+id/bu4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
       >
        <TextView
        android:id="@+id/title4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="圆环的颜色" 
        />
        <EditText 
            android:id="@+id/ed4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="9"/>
    </LinearLayout>
    <Button 
        android:id="@+id/but5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="绘图"/>
    <view.LegePaint
        android:id="@+id/mlegeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>

Stkcd [股票代码] ShortName [股票简称] Accper [统计截止日期] Typrep [报表类型编码] Indcd [行业代码] Indnme [行业名称] Source [公告来源] F060101B [净利润现金净含量] F060101C [净利润现金净含量TTM] F060201B [营业收入现金含量] F060201C [营业收入现金含量TTM] F060301B [营业收入现金净含量] F060301C [营业收入现金净含量TTM] F060401B [营业利润现金净含量] F060401C [营业利润现金净含量TTM] F060901B [筹资活动债权人现金净流量] F060901C [筹资活动债权人现金净流量TTM] F061001B [筹资活动股东现金净流量] F061001C [筹资活动股东现金净流量TTM] F061201B [折旧摊销] F061201C [折旧摊销TTM] F061301B [公司现金流1] F061302B [公司现金流2] F061301C [公司现金流TTM1] F061302C [公司现金流TTM2] F061401B [股权现金流1] F061402B [股权现金流2] F061401C [股权现金流TTM1] F061402C [股权现金流TTM2] F061501B [公司自由现金流(原有)] F061601B [股权自由现金流(原有)] F061701B [全部现金回收率] F061801B [营运指数] F061901B [资本支出与折旧摊销比] F062001B [现金适合比率] F062101B [现金再投资比率] F062201B [现金满足投资比率] F062301B [股权自由现金流] F062401B [企业自由现金流] Indcd1 [行业代码1] Indnme1 [行业名称1] 季度数据,所有沪深北上市公司的 分别包含excel、dta数据文件格式及其说明,便于不同软件工具对数据的分析应用 数据来源:基于上市公司年报及公告数据整理,或相关证券交易所、各部委、省、市数据 数据范围:基于沪深北证上市公司 A股(主板、中小企业板、创业板、科创板等)数据整理计算
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值