简体   繁体   中英

retain previous position of floating action button android

我想在应用程序关闭时保留浮动操作按钮的位置,并在再次打开应用程序时在以前的位置再次显示FAB。

store the previous position of floating action button before moving like this

LayoutParams positionOfButton = floatingActionButton.getLayoutParams();

and again when it is needed to restore button to its original position do this,

floatingActionButton.setLayoutParams(positionOfButton);

You can achieve this using the sharedPreferences concept. You have to capture the coordinates of FAB and store them in preferences.

 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM