Fra*_*sco 3 android android-layout
我正在尝试创建一个Android应用程序,为图像添加随机引用.
一般过程是这样的:
我已经到了可以在ImageView中显示图像的地步.
我的引号列表存储在我的strings.xml文件中.
我在应用程序中做了类似的事情.使用画布.
我编辑了一段代码,实际上在背景上添加了几个其他图像.
代码肉:
private static Bitmap getPoster(...) {
Bitmap background = BitmapFactory.decodeResource(res, background_id)
.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(background);
Typeface font = Typeface.createFromAsset(res.getAssets(), FONT_PATH);
font = Typeface.create(font, Typeface.BOLD);
Paint paint = new Paint();
paint.setTypeface(font);
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
paint.setShadowLayer(2.0f, 1.0f, 1.0f, Color.BLACK);
float fontSize = getFontSize(background.getWidth(), THE_QUOTE, paint); //You'll have to define a way to find a size that fits, or just use a constant size.
paint.setTextSize(fontSize);
canvas.drawText(THE_QUOTE, (background.getWidth() - paint.measureText(THE_QUOTE)) / 2,
background.getHeight() - FILLER_HEIGHT, paint); //You might want to do something different. In my case every image has a filler in the bottom which is 50px.
return background;
}
Run Code Online (Sandbox Code Playgroud)
将您自己的版本放在一个类中,并为其提供图像ID和其他任何内容.它返回一个位图,供您随意使用(在imageview中显示,让用户保存并设置为wallpape).
| 归档时间: |
|
| 查看次数: |
4401 次 |
| 最近记录: |