[英]retain previous position of floating action button android
我想在应用程序关闭时保留浮动操作按钮的位置,并在再次打开应用程序时在以前的位置再次显示FAB。
像这样移动之前,存储浮动操作按钮的先前位置
LayoutParams positionOfButton = floatingActionButton.getLayoutParams();
再次需要将按钮恢复到原始位置时,
floatingActionButton.setLayoutParams(positionOfButton);
您可以使用sharedPreferences概念来实现。 您必须捕获FAB的坐标并将其存储在首选项中。
SharedPreferences sp=getSharedPreferences("values",0);
int[] i=new int[2];
FAB.getLocationOnScreen(i);
sp.edit().putString(i[0]+"").commit();
sp.edit().putString(i[1]+"").commit();
//while retrieving parse to double. and then set
FAB.setX(x);
FAB.setY(y); //where x and y are double values from sharedpreferences.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.