Path path = new Path();
path.moveTo(50, 0);
path.lineTo(0, 50);
path.lineTo(50, 100);
path.lineTo(100, 50);
//封闭前面点所绘制的路径
path.close();
ShapeDrawable mDrawables = new ShapeDrawable(new PathShape(path, 100, 100));
How does this path object 4 vertex coordinates should be a square , why is a rhombus drawn effect . PathShape constructor after the two parameters is how it works , sometimes 100 , sometimes 150 , do not know how to calculate . Whether the shape of the polygon and setBounds (int left, int top, int right, int bottom)
methods relevant , expert answer, thank you
------ Solution ---------------------------- ----------------
is what I want to learn a simple example trapezoidal
PathShape (path1, 150,150)
mShapeDrawable.setBounds (100, 170, 200, 280);
x = 100 + (200-100) / 150 * (150 +5)
y = 170 + (280-170) 150 * (80 +80-50)
setBounds the offset is the absolute coordinates on the canvas to be multiplied by the amplification factor job
------ eference --------------- ------------------------
path.moveTo (0, 0);
path.lineTo (0, 100);
path.lineTo (100, 100);
path.lineTo (100, 0);
This is a square bar ... LZ that painting is the diamond . . .
------ eference --------------------------------------- < br>
this square is the bottom two sides are parallel to the top edge of the screen .
And my square was " Shuidao " and painted with coordinates know .
------ eference --------------------------------------- < br> nobody knows the answer it ?
------ eference -------------------------------- -------
• The setBounds (Rect) method must be called to tell the Drawable where it is drawn and how large it ; should be. All Drawables should respect the requested size, often simply by scaling their imagery .
and setBounds on , or are automatically set into a square drawn here can
------ eference -------------------- -------------------
Path path = new Path();
path.moveTo(50, 0);
path.lineTo(0, 50);
path.lineTo(50, 100);
path.lineTo(100, 50);
//封闭前面点所绘制的路径
path.close();
ShapeDrawable mDrawables = new ShapeDrawable(new PathShape(path, 100, 100));
setBounds(0,0,300,50);
just sustain full , forming a diamond, the relationship between these values is kind of how it
------ eference ------------------------------------ ---
here set setBounds (0, 0, 100, 100); is the original size of the
relationship is such that
setBounds (0, 0, x, y);
PathShape (path, 100,100);
proportional size is x/100 y/100
If setBounds (0, 0, 200, 300); x zoom magnification 3 times 2 times y
public PathShape (Path path, float stdWidth, float stdHeight)
Since: API Level 1 PathShape constructor.
Parameters
path a Path that defines the geometric paths for this shape
stdWidth the standard width for the shape. Any changes to the width with resize () will result in a width scaled ; based on the new width divided by this width .
stdHeight the standard height for the shape. Any changes to the height with resize () will result in a height scaled ; based on the new height divided by this height.
------ eference ------------------------------------ ---
explain more on the 6th floor , a bit puzzled .
mShapeDrawable.setBounds(70, 250, 150, 280);////此处画个椭圆
/* 绘制图像 */
mShapeDrawable.draw(canvas);
Path path1 = new Path();
/*设置多边形的点*/
path1.moveTo(150+5, 80+80-50);
path1.lineTo(150+45, 80+80-50);
path1.lineTo(150+30, 80+120-50);
path1.lineTo(150+20, 80+120-50);
/* 使这些点构成封闭的多边形 */
path1.close();
//PathShape后面两个参数分别是宽度和高度
mShapeDrawable = new ShapeDrawable(new PathShape(path1,150,150));
//得到画笔paint对象并设置其颜色
mShapeDrawable.getPaint().setColor(Color.BLUE);
/* 设置图像显示的区域 */
mShapeDrawable.setBounds(100, 170, 200, 280);
/* 绘制图像 */
mShapeDrawable.draw(canvas);
I want to know the location of this ladder is how determined , how and elliptical vertical alignment ?
------ eference --------------------------------------- < br>
Path path1 = new Path();
path1.moveTo(5, 0);
path1.lineTo(45, 0);
path1.lineTo(30, 40);
path1.lineTo(20, 40);
path1.close();
path1 not shifted , trapezoidal position offset with setBounds set a good calculation on the line .
mShapeDrawable.setBounds (100, 170, 200, 280); width calculated here is 100 , high 110
and your new PathShape (path1, 150,150) is not the same , here are automatically scaled down .
------ eference ------------------------------------ ---
two tone setBounds coordinate set parameters can be aligned
------ eference ---------------------- -----------------
thanks fontlose!
1, path1 is set in such a way , is not there ( 5,0 ) offset ? This offset , there is no corresponding scaling ( eg : proportional size is x/100)
2,
path1.moveTo(150+5, 80+80-50);
path1.lineTo(150+45, 80+80-50);
path1.lineTo(150+30, 80+120-50);
path1.lineTo(150+20, 80+120-50);
mShapeDrawable.setBounds(100, 170, 200, 280);
trapezoidal top how Located in y = 250 , and feels like 80 +170 look, do not know why
------ eference ------------- --------------------------
1. Yes, you can also subtract 5 should be the most simple
Path path1 = new Path ();
path1.moveTo (0, 0);
path1.lineTo (40, 0);
path1.lineTo (25, 40);
path1.lineTo (15, 40);
path1.close ();
2. This should be in the x = 255 y = 280 on the bar, it wants to add two offsets
------ eference ------------------------------------ ---
/* 实例化ShapeDrawable对象并说明是绘制一个矩形 */
mShapeDrawable = new ShapeDrawable(new RectShape());
//得到画笔paint对象并设置其颜色
mShapeDrawable.getPaint().setColor(Color.RED);
Rect bounds = new Rect(5, 250, 55, 280);
/* 设置图像显示的区域 */
mShapeDrawable.setBounds(bounds);
This trapezoid and the rectangle parallel
Take the y-axis , is from y = 250 ~ 280 , the current place if the simple addition , it becomes y = 280 ~ 320.
book so write code path1.moveTo (150 +5, 80 +80-50); may have a good understanding of the algorithm
------ eference ----- ----------------------------------
Well, this algorithm should be right up . Scaling the coordinates of points on the canvas , do not know how much practical application .
------ eference --------------------------------------- < br>
没有评论:
发表评论