我正在使用下面的代码在android画布上绘制文本
Rect rect = new Rect();
paint.getTextBounds(text, 0, text.length(), rect);
canvas.translate(xPosition + position.getX(), yPosition + position.getY());
paint.setColor(Color.BLUE);
paint.setStyle(Style.STROKE);
canvas.drawRect(rect, paint);
paint.setStyle(Style.FILL);
paint.setColor(text_color);
canvas.translate(-(xPosition + position.getX()), -(yPosition + position.getY()));
canvas.rotate(getDegreesFromRadians(angle), xPosition + position.getX() + rect.exactCenterX(), yPosition + position.getY() + rect.exactCenterY());
canvas.drawText(text, xPosition + position.getX(), yPosition + position.getY(), paint);
Run Code Online (Sandbox Code Playgroud)
此代码负责文本的旋转,并且工作正常.我正在使用上面的代码在文本周围绘制一个蓝色矩形.现在我的问题是矩形不随文本一起旋转.它仍然保持不变.有没有办法旋转Android画布中绘制的矩形?
我试图在画布上绘制一个简单的Rect,它的X坐标为360,Y坐标为0.如果我将X坐标设为0,我可以绘制我的Rect,但是当我将它设为360时,正方形变得扭曲,变成矩形而不是正方形.我的屏幕尺寸是640px宽,所以这里应该没问题.我可以用相同的规格绘制位图,它会正常绘制.为什么Rects没有正确绘制?是不是以某种方式X坐标只在DP而不是PX?那为什么会影响Rect的实际大小?我真的很困惑.
Rect square6 = new Rect();
square6.set(360, 0, 60, 60);
Run Code Online (Sandbox Code Playgroud) 我想使用方面适合选项将一个视图插入到另一个视图中。但是contentMode由于某些原因我不能设置。
您能否通过CGRect根据外部调整内部大小来提供解决方案CGRect?
是的,有很多类似的问题,但没有人提供这样的解决方案。
我想知道如何检查Unity Canvas上的两个UI面板是否相互重叠。
目前,我正在通过比较画布元素Rects来做到这一点
画布设置
画布缩放器设置
我正在检查的代码
[Header("Check For Overlap")]
public RectTransform PlayerBar;
public RectTransform LeftBar;
public Rect RectOne;
public Rect RectTwo;
public bool overlapping;
//Check if the two canvas element Rects overlap each other
public void CheckForOverlap()
{
overlapping = false;
// Convert Canvas RectTransforms to World Rects
RectOne = GetWorldRect(LeftBar);
RectTwo = GetWorldRect(PlayerBar);
if (RectOne.Overlaps(RectTwo))
{
overlapping = true;
}
}
public Rect GetWorldRect(RectTransform rt)
{
// Get World corners, …Run Code Online (Sandbox Code Playgroud) 我正在实例化一个GO,它有一个面板组件(RectTransform)作为场景中存在的画布的子代:
_heroSelectUI = (GameObject)Instantiate (_heroSelectUIPrefab, GameObject.Find ("Canvas").GetComponent<Transform>());
Run Code Online (Sandbox Code Playgroud)
创建它时,它获得以下值:
"左","上","右"和"下"得到一些不需要的值(可能是由于现有的画布似乎具有相同的值).
面板预制值为0,如何在实例化后将它们设置为0?我找不到RectTransform的正确变量.
我想创建一个在其轴上旋转正方形的函数。
var halfWidth = canvas.width/2;
var halfHeight = canvas.height/2;
var x = halfWidth-10;
var y = halfHeight-10;
var w = 20;
var h = 20;
var deg = 45;
rotate(x, y, w, h, deg);
ctx.fillRect(x, y, w, h);
Run Code Online (Sandbox Code Playgroud)
功能:
function rotate(x, y, w, h, deg) {
// ctx.translate() and ctx.rotate()
// goes here.
}
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
我正在使用nvd3.js库及其水平图http://nvd3.org/ghpages/multiBarHorizontal.html 我试图通过以下css在栏之间添加一些边距但是不起作用. http://jsfiddle.net/petran/x7Cdz/1/
rect {
display: inline-block;
margin-top: 25px;
margin-bottom: 5px;}
Run Code Online (Sandbox Code Playgroud)
还有另一种方法可以实现吗?
我想为视图添加边框,边框宽度,颜色,半径可以由用户设置.所以我试着为它绘制一个矩形.当我使用drawRoundRect绘制时,角落处的线条不平滑,它也比其他地方更粗.我不知道如何解决它.请给我一些指导.还有其他办法吗?我必须使用代码来绘制它.
非常感谢.附加代码:rect的红色角落.过去的代码:
public class MPCTextView extends TextView {
// private Context context;
private final static String TAG = "MPCTextView";
public final static int DEFAULT_BACKGROUND_COLOR = Color
.parseColor("#28FF28");
public final static int DEFAULT_BORDER_COLOR = Color.parseColor("#FF0000");
public int mBoderWidth = 2;
public int mBoderColor;
public int mBoderRadius = 20;
public int mbackgroundColor;
public boolean isHaveBorder = true;
public boolean isHaveBackground = true;
RectF mRectF = new RectF();
Rect mRec = new Rect();
Paint mPaint = new Paint();
public MPCTextView(Context context) {
super(context); …Run Code Online (Sandbox Code Playgroud) 我有一个矩形,比如说, rect1 。我有另一个名为 rect2 的矩形。我想 blit 'rect2' 以便 rect2 的中心与 rect1 的中心相同?
rect ×10
android ×3
c# ×2
draw ×2
pygame ×2
aspect-fit ×1
cgrect ×1
html ×1
html5-canvas ×1
ios ×1
javascript ×1
margins ×1
nvd3.js ×1
objective-c ×1
outline ×1
panel ×1
python ×1
rotation ×1
svg ×1
transform ×1
transparent ×1
width ×1