我想知道Instagram或Snapchat等其他应用程序使用什么功能或库在图像上添加文本,然后将它们都发布为图像。谁能帮助我在android中了解这一点
我已经尝试在框架布局的图像视图上使用文本视图,但是这样做不值得
答案 0 :(得分:0)
您可以使用RelativeLayout
class MultiCheckBoxField extends StatelessWidget {
const MultiCheckBoxField({
Key key,
this.count = 1,
this.onSaved,
}) : super(key: key);
final int count;
final FormFieldSetter<List<bool>> onSaved;
@override
Widget build(BuildContext context) {
return FormField<List<bool>>(
initialValue: List.filled(count, false),
onSaved: onSaved,
builder: (FormFieldState field) {
return Column(
mainAxisSize: MainAxisSize.min,
children: List.generate(
count,
(int index) {
return Checkbox(
onChanged: (bool value) {
field.value[index] = value;
field.didChange(field.value);
},
value: field.value[index],
);
},
),
);
},
);
}
}
答案 1 :(得分:0)
您可以根据需要创建视图,然后将视图转换为位图。
<RelativeLayout
android:id="@+id/myView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="My text" />
</RelativeLayout>
将上述视图的ID( @ + id / myView )发送到以下函数以获取位图
public static Bitmap getBitmapFromView(View view) {
view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.draw(canvas);
return bitmap;
}