[英]Save/restore state of custom views in android
您需要存储所有编辑内容:
Rotation
:为此,您必须保持从初始值0到下一个旋转值的角度。
Flip
:为此创建一个标志,并为正面和背面设置True,false值。
Text
:你知道怎么把文字从EditText
取EditText
。
Layout position within parent View
:
用于计算父视图中的布局位置使用下面的方法并为此创建四个int变量,
Left
=
Top
=
Right
=
Bottom
=
Height
=
Width
=
private Map<String,Integer> getPositionOnScreen(View view){
Map<String,Integer> map = new HashMap<String,Integer>();
View rootLayout = view.getRootView().findViewById(android.R.id.content);
int[] viewLocation = new int[2];
view.getLocationOnScreen(viewLocation);
int[] rootLocation = new int[2];
rootLayout.getLocationOnScreen(rootLocation);
int relativeLeft = viewLocation[0] - rootLocation[0];
int relativeTop = viewLocation[1] - rootLocation[1];
int height = viewLocation[0] - rootLocation[0];
int width = viewLocation[1] - rootLocation[1];
map.put("left",relativeLeft);
map.put("top",relativeTop);
map.put("height",view.getLayoutParams().height);
map.put("width",view.getLayoutParams().width);
return map;
}
上面的方法返回左视图和顶视图的位置,但您需要从左,顶部和高度,宽度计算右下角位置。
创建一个Pojo以将所有这些参数保存在一起,并将此pojo存储到SharedPreferences或Data Base或Application Context中。
这是最简单的方法
最后,经过几天的搜索,我得到了一个解决方案。
有一个名为StickerView的库,它有助于使用Matrix
存储特定Drawable Sticker或任何Text Sticker的数据,并且可以使用StickerView
的对象存储许多细节,并且可以根据应用程序的要求进行自定义。
还有一个类似于这个StickerView的库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.