首页 > 代码库 > Canvas Path 绘制柱体
Canvas Path 绘制柱体
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()).commit(); } } /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } ImageView drawingImageView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); drawingImageView = (ImageView)rootView.findViewById(R.id.drawingImageView); int width = (int) getActivity().getWindowManager().getDefaultDisplay().getWidth(); int height = (int)getActivity().getWindowManager().getDefaultDisplay().getHeight(); Bitmap bitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawingImageView.setImageBitmap(bitmap); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.GREEN); Path p = new Path(); float offsetX = 30; float offsetY = 30; //正面 p.moveTo(0.75f, 60f); p.lineTo(0.75f, 229.1f); p.lineTo(92.5f, 229.1f); p.lineTo(92.5f, 60f); p.lineTo(0.75f, 60f); canvas.drawPath(p, paint); //右侧面 p.reset(); p.moveTo(92.5f, 60f); p.lineTo(92.5f, 229.1f); p.lineTo(92.5f+offsetX, 229.1f-offsetY); p.lineTo(92.5f+offsetX, 60f-offsetY); p.lineTo(92.5f, 60f); canvas.drawPath(p, paint); //上面 p.reset(); p.moveTo(0.75f+offsetX, offsetY); p.lineTo(0.75f, 60f); p.lineTo(92.5f, 60f); p.lineTo(92.5f+offsetX, 60f-offsetY); p.lineTo(0.75f+offsetX, offsetY); canvas.drawPath(p, paint); //针对上面,绘制一个白色的菱形强化立体效果 paint.reset(); paint.setStyle(Style.STROKE); paint.setColor(Color.WHITE); p.reset(); p.moveTo(0.75f+offsetX, offsetY); p.lineTo(0.75f, 60f); p.lineTo(92.5f, 60f); p.lineTo(92.5f+offsetX, 60f-offsetY); p.lineTo(0.75f+offsetX, offsetY); canvas.drawPath(p, paint); //针对右侧面,绘制一个白色菱形强化立体效果 p.reset(); p.moveTo(92.5f, 60f); p.lineTo(92.5f, 229.1f); p.lineTo(92.5f+offsetX, 229.1f-offsetY); p.lineTo(92.5f+offsetX, 60f-offsetY); p.lineTo(92.5f, 60f); canvas.drawPath(p, paint); return rootView; } }}
Canvas Path 绘制柱体
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。