簡體   English   中英

保留浮動動作按鈕android的先前位置

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM