保留浮动动作按钮android的先前位置

时间:2016-12-27 04:57:14

标签: android android-layout

我希望在应用关闭时保留浮动操作按钮的位置,并在再次打开应用时再次显示前一个位置的FAB。

2 个答案:

答案 0 :(得分:0)

在像这样移动之前存储浮动动作按钮的先前位置

annotate

再次需要将按钮恢复到原始位置时执行此操作,

LayoutParams positionOfButton = floatingActionButton.getLayoutParams();

答案 1 :(得分:-1)

您可以使用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.
相关问题