我是靠谱客的博主 紧张溪流,这篇文章主要介绍Android动态实现shape,android – 动态创建一个Shape,现在分享给大家,希望可以做个参考。

例:

import android.graphics.drawable.GradientDrawable;

public class SomeDrawable extends GradientDrawable {

public SomeDrawable(int pStartColor, int pCenterColor, int pEndColor, int pStrokeWidth, int pStrokeColor, float cornerRadius) {

super(Orientation.BOTTOM_TOP,new int[]{pStartColor,pCenterColor,pEndColor});

setStroke(pStrokeWidth,pStrokeColor);

setShape(GradientDrawable.RECTANGLE);

setCornerRadius(cornerRadius);

}

}

用法:

public class MyActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

SomeDrawable vDrawable = new SomeDrawable(Color.BLACK,Color.GREEN,Color.LTGRAY,2,Color.RED,50);

View vView = new View(this);

vView.setBackgroundDrawable(vDrawable);

setContentView(vView);

}

}

结果:

最后

以上就是紧张溪流最近收集整理的关于Android动态实现shape,android – 动态创建一个Shape的全部内容,更多相关Android动态实现shape,android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(123)

评论列表共有 0 条评论

立即
投稿
返回
顶部