1
我在LinearLayout中有10個frameLayout。在我的應用程序中,我可以移動這些框架,但如果關閉它,我的框架位置不會保存。如果我再次打開應用程序,我會看到我的幀的默認位置? 如何保存位置?幫幫我!! P.S.在我的應用程序中,我使用sharedPreferences。如何保存視圖組件的位置?
我在LinearLayout中有10個frameLayout。在我的應用程序中,我可以移動這些框架,但如果關閉它,我的框架位置不會保存。如果我再次打開應用程序,我會看到我的幀的默認位置? 如何保存位置?幫幫我!! P.S.在我的應用程序中,我使用sharedPreferences。如何保存視圖組件的位置?
,可以使用共享首選項來存儲的東西在內存中,並在以後的時間恢復他們: Android docs for SharedPreferences
實例 - 在存儲和恢復的整數叫做位置:
int position = 0;
//get the SharedPreferences for "yourContextName", which you need to replace it with you context name
SharedPreferences pref = getSharedPreferences("yourContextName", Context.MODE_PRIVATE);
/* --------------- Storing data -------------------- */
//Get editor for writing data to memory
SharedPreferences.Editor editor = pref.edit();
//Add an integer to editor
editor.putInt("position", position);
//Must commit or else the data will NOT be stored
editor.commit();
/* ---------------- Retrievig data ------------------ */
//Retrievig an integer from pref with tag "position" (-1 is the default value)
int retInt = pref.getInt("position", -1);
我如何使用這個例如我的情況:在滾動視圖>在LinearLayout:我移動10 FrameLayouts?我需要在LinearLayout中爲我的FrameLayout保存郵件。我只找到.getVerticalScrollbarPosition。這是我需要的嗎? – JerryLetehen