Last active
August 29, 2015 14:14
-
-
Save wasnot/34488277433daa246bb1 to your computer and use it in GitHub Desktop.
ShapeDrawableの放射線状のグラデーションの半径指定について ref: http://qiita.com/wasnot/items/1e6794fbc047101756a6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources ...> | |
... | |
<item name="radius" format="float" type="dimen">200.34</item> | |
.... | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |
<gradient | |
android:centerX="0.4" | |
android:centerY="0.6" | |
android:endColor="#090e1c" | |
android:gradientRadius="800" | |
android:startColor="#314036" | |
android:type="radial" | |
/> | |
<!-- | |
解像度や使い回しのためにこんな風に書きたい! | |
android:gradientRadius="800dp" | |
android:gradientRadius="80%" | |
--> | |
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error:(9, 45) Dimension types not allowed (at 'gradientRadius' with value '5dp'). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android:gradientRadius="50" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android:gradientRadius="50%" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android:gradientRadius="5000%" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 背景に指定してるDrawableを取得して編集。。 | |
((GradientDrawable) someView.getBackground()) | |
.setGradientRadius(getResources().getDimension( | |
R.dimen.yellowbadge_largeradius)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Paint mPaint; | |
RadialGradient mGradient; | |
private void init(){ | |
// PaintとかはonDrawで確保しないほうがいいですね。。Gradientも? | |
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
} | |
@Override | |
protected void onDraw(Canvas canvas) { | |
int maxSize = Math.max(getHeight(), getWidth()); | |
// RadialGradientを作って書く。 | |
// コンストラクタでattrを見るようにすればxmlで色々できますね。 | |
mGradient = new RadialGradient( | |
getWidth()/2, | |
getHeight()/2, | |
maxSize, | |
new int[] {Color.RED, Color.BLACK}, | |
new float[] {0, 1}, | |
android.graphics.Shader.TileMode.CLAMP); | |
// PaintにGradientをセット | |
mPaint.setDither(true); | |
mPaint.setShader(mGradient); | |
// View全体に描画, paddingも考慮すべきですね。。。 | |
canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape="rectangle"> | |
<gradient | |
android:startColor="#7faacaFF" | |
android:endColor="#cfe1edFF" | |
android:gradientRadius="@dimen/radius" | |
android:type="radial"/> | |
</shape> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment