设为首页 加入收藏

TOP

Android打造带透明圆弧的ImageView(三)
2017-10-13 09:49:55 】 浏览:7246
Tags:Android 打造 透明 圆弧 ImageView
Color = ta.getColor(R.styleable.ArcImageView_arcColor, 0XCCCCCC); 226 mTextColor = ta.getColor(R.styleable.ArcImageView_textColor, 0XFFFFFF); 227 mDrawStyle = ta.getInt(R.styleable.ArcImageView_drawStyle, 0); 228 ta.recycle(); 229 } 230 }

2.在values文件夹下的attrs.xml中自定义属性:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <resources>
 3     <declare-styleable name="ArcImageView">
 4         <attr name="drawStr" format="string" />
 5         <attr name="textSize" format="dimension" />
 6         <attr name="arcAlpha" format="integer" />
 7         <attr name="arcWidth" format="integer" />
 8         <attr name="startAngle" format="integer" />
 9         <attr name="sweepAngle" format="integer" />
10         <attr name="scale" format="float" />
11         <attr name="hOffset" format="float" />
12         <attr name="vOffset" format="float" />
13         <attr name="drawStyle" format="enum">
14             <enum name="LEFT_TOP" value="0" />
15             <enum name="LEFT_BOTTOM" value="1" />
16             <enum name="RIGHT_TOP" value="2" />
17             <enum name="RIGHT_BOTTOM" value="3" />
18             <enum name="CENTER" value="4" />
19         </attr>
20         <attr name="arcColor" format="color" />
21         <attr name="textColor" format="color" />
22     </declare-styleable>
23 </resources>

3.在MainActivity调用ArcImageView,实现代码如下:

 1 package com.chunk.customviewsdemo;
 2 
 3 import android.os.Bundle;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.view.View;
 6 import android.widget.Button;
 7 
 8 import com.chunk.customviewsdemo.views.ArcImageView.ArcImageView;
 9 
10 public class MainActivity extends AppCompatActivity implements View.OnClickListener {
11     private ArcImageView aiv_one;
12     private ArcImageView aiv_two;
13     private ArcImageView aiv_three;
14     private ArcImageView aiv_four;
15     private Button btn_another_one;
16     private int mGroup = 1;
17 
18     @Override
19     protected void onCreate(Bundle savedInstanceState) {
20         super.onCreate(savedInstanceState);
21         setContentView(R.layout.activity_main);
22         aiv_one = (ArcImageView) findViewById(R.id.aiv_one);
23         aiv_one.setArcAlpha(180);
24         aiv_two = (ArcImageView) findViewById(R.id.aiv_two);
25         aiv_two.setArcAlpha(180);
26         aiv_three = (ArcImageView) findViewById(R.id.aiv_three);
27         aiv_three.setArcAlpha(180);
28         aiv_four = (ArcImageView) findViewById(R.id.aiv_four);
29         aiv_four.setArcAlpha(180);
30         btn_another_one = (Button) findViewById(R.id.btn_another_one);
31         btn_another_one.setOnClickListener(this);
32     }
33 
34     @Override
35     public void onClick(View v) {
36         switch (v.getId()) {
37             case R.id.btn_another_one:
38                 if (mGroup == 1) {
39                     aiv_one.setDrawStr("苹果");
40                     aiv_one.setBackgroundResource(R.drawable.apple);
41                     aiv_two.setDrawStr("柚子");
42                     aiv_two.setBackgrou
首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android之Proguard语法 下一篇利用android studio gsonformat插..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目