我试图制作一个drawable用于按钮.我希望它有这种颜色,周围有2px边框.
一切都很好,除了我不能让边界出现......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient android:startColor="@color/bar_clicked_dark"
android:endColor="@color/bar_clicked_light"
android:angle="90"/>
<corners android:bottomLeftRadius="0dp"
android:topLeftRadius="15dp"
android:bottomRightRadius="15dp"
android:topRightRadius="0dp" />
<stroke android:width="2dp"
color="#ff00ffff" />
</shape>
Run Code Online (Sandbox Code Playgroud) 我需要从应用程序中更改笔触颜色.用户可以更改背景颜色,因此我还需要让他们更改按钮的笔触(轮廓).由于它已经在drawable(下面的示例)中设置,我还没有找到改变它的方法.看起来像所有其他问题只是说使用XML文件......但这并不能让我变得动态.感谢您的任何帮助!
我需要将笔触颜色更改为用户定义的颜色.与国家无关.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff"/>
<stroke
android:width="3dp"
android:color="@color/Dim_Gray" /> <<<<--- This is what I need to change
<padding android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"
/>
<corners android:bottomRightRadius="12dp" android:bottomLeftRadius="12dp"
android:topLeftRadius="12dp" android:topRightRadius="12dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud) 我正在使用svg创建股票图表,当我将路径元素的笔触宽度设置为1时,我遇到了问题.而不是使线条更窄,它只是使它与笔划宽度相同:2但略透明.我不能发布它的图像,因为我没有足够的声誉点...
我的svg标签看起来像这样:
<div style="height:300px; width:400px; overflow:hidden">
<svg style="position:relative" height="10000" width="10000" version="1.1" xmlns="http://www.w3.org/2000/svg">
</svg>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在使用javascript/jquery动态添加路径元素:
var shape = document.createElementNS("http://www.w3.org/2000/svg", "path");
$(shape).attr({"d":"...",
"fill":"none",
"stroke":color,
"stroke-width":"1"});
$("svg").append(shape);
Run Code Online (Sandbox Code Playgroud)
我省略了路径d属性的值,因为它有点长.此外,color是一个字符串变量,它在前面确定为"绿色","红色"或"黑色".
我的代码中是否存在导致此问题的错误或是否是另一个问题?
鉴于此代码绘制一条线:
Paint p;
p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(android.graphics.Color.WHITE);
p.setStyle(Paint.Style.FILL);
p.setStrokeWidth(21);
canvas.drawLine(0,50,100,50,p);
Run Code Online (Sandbox Code Playgroud)
有3种可能的描笔策略:
在实践中,似乎默认行为遵循中心策略.是否可以修改油漆以产生与其他策略相对应的结果?
我正在使用此代码来获取两点之间的方向.是否可以从蓝色改变路线的颜色?我在代码中没有使用折线.
提前Thanx :)
我试图让用户在画布上绘制一个矩形(如选择框).我得到了一些可笑的结果,但后来我发现,从我的参考,甚至只是想代码在这里,我得到巨大的模糊线,不知道为什么.
它托管在dylanstestserver.com/drawcss.javascript是内联的,所以你可以检查出来.我正在使用jQuery来简化鼠标坐标.
我在扩展视图中有一些代码设置,它可以做一些容易缩放的绘图(类似矢量).(我的比例设置为0-1.0)
我注意到当我将绘制填充设置为FILL时,路径上绘制的文本看起来是正确的,但是当我将填充设置为笔划(我只想要文本的轮廓)时,图像看起来就像是在某个LSD行程中.这是我的示例代码:
Paint yellowPaint = Paints.getFillTextPaint(0.01f, 0xFFffea3e, 0.065f);
canvas.drawTextOnPath(mContext.getString(R.string.building_a_partnership),
Paths.getRoundedTextPath(mOuterCircleRectF, 280f, 350f),
0, -0.025f, yellowPaint);
public static Paint getFillTextPaint(float f, int color, float textSize) {
Paint textPaint = new Paint();
textPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
textPaint.setStyle(Paint.Style.FILL);
textPaint.setColor(color);
textPaint.setTextSize(textSize);
textPaint.setStrokeWidth(f);
textPaint.setShadowLayer(0.002f, 0.0f, 0.0f, 0xFF000000);
textPaint.setTypeface(Typeface.SANS_SERIF);
return textPaint;
}
Run Code Online (Sandbox Code Playgroud)
如果我将Paint.Style从FILL更改为STROKE,我会得到下面的图像.我使用了canvas.drawText(),它可以很好地显示描边字母.只有当它应用于Path时才会变得奇怪.


我创建了一个矩形形状,以便将其用作列表项背景.我的问题是笔划不遵循视图边框但是让笔划宽度为+/-.
这是我的形状的xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="1"
android:shape="rectangle" >
<solid android:color="@color/deminoir" />
<stroke
android:width="4dp"
android:color="@color/deminoir" />
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
这是我的风格的xml:
<style name="champ">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">vertical</item>
<item name="android:background">@drawable/bordurechamp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
最后是我的列表项视图的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/champ" >
<!-- titre -->
<TextView
android:id="@+id/titre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/deminoir"
android:padding="5dip"
android:text="titre"
android:textAppearance="@android:style/TextAppearance.Large" />
<!-- Contenu -->
<TextView
android:id="@+id/valeur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dip"
android:text="valeur"
android:textAppearance="@android:style/TextAppearance.Medium"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我有一个小的svg小部件,其目的是显示一个角度列表(见图).
现在,角度是线条元素,只有笔划而没有填充.但现在我想要一个"内部填充"颜色和围绕它的"笔划/边框".我猜测线元素无法处理,所以我应该使用什么呢?
请注意,线条笔划的line-endcap是圆角的.我想在解决方案中保持这种效果.

<svg height="160" version="1.1" viewBox="-0.6 -0.6 1.2 1.2" width="160" xmlns="http://www.w3.org/2000/svg">
<g>
<g>
<circle class="sensorShape" cx="0" cy="0" fill="#FFF" r="0.4" stroke="black" stroke-width="0.015"/>
<line stroke="black" stroke-width="0.015" x1="0" x2="0" y1="-0.4" y2="0.4"/>
<line stroke="black" stroke-width="0.015" x1="-0.4" x2="0.4" y1="0" y2="0"/>
</g>
<g class="lsNorthAngleHandsContainer">
<line data-angle="348" stroke="red" stroke-linecap="round" stroke-width="0.04" transform="rotate(348)" x1="0" x2="0" y1="0" y2="-0.4"/>
<text font-size="0.08" transform="translate(-0.02316467632710395,-0.45125904029352226)">
348
</text>
</g>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud) 我一直UIBezierPath用Swift 做一个简单的动画.此路径包括创建带有彩色边框的圆角矩形.动画必须是彩色边框的绘图.为此,我创建了一个CAShapeLayer带有UIBezierPath(roundedRect:, cornerRadius: )
let layer = CAShapeLayer()
var viewPrueba = UIView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
viewPrueba = UIView(frame: CGRectMake(self.view.frame.width/2-100, self.view.frame.height/2 - 100, 200, 200))
self.view.addSubview(viewPrueba)
let path = UIBezierPath(roundedRect: CGRectMake(0, 0, 200, 200), cornerRadius: 40.0)
layer.path = path.CGPath
layer.fillColor = UIColor.clearColor().CGColor
layer.strokeColor = UIColor.blueColor().CGColor
layer.strokeStart = 0.0
layer.strokeEnd = 0.0
layer.lineWidth = 4.0
layer.lineJoin = kCALineJoinRound
viewPrueba.layer.addSublayer(layer)
let tapGR = …Run Code Online (Sandbox Code Playgroud)