android– 如何在更改方向时保持ViewFlipper中的当前视图

android– 如何在更改方向时保持ViewFlipper中的当前视图,第1张

概述有没有什么好方法可以在ViewFlipper中保持当前视图,而sill能够加载layout-port文件夹?也许使用onRetainNonConfigurationInstance()?如果是这样,我将如何实施呢?我尝试了一些推杆解决方案:android:configChanges="orientation|keyboardHidden"在清单中.问题是Android然后忽略我的

有没有什么好方法可以在VIEwFlipper中保持当前视图,而sill能够加载layout-port文件夹?也许使用onRetainNonConfigurationInstance()?如果是这样,我将如何实施呢?我尝试了一些推杆解决方案:

androID:configChanges="orIEntation|keyboardHIDden"

在清单中.

问题是AndroID然后忽略我的布局端口文件夹,它重新排列输入字段和按钮.

–Update–

这是我添加了hooked82代码的代码.我添加了抛出错误的部分:

public class AtriumMain extends Activity {    Login login = new Login();    String username, password;    EditText user, pass, servername, propertyID;    Context context;    CharSequence text;    int duration, settingsClicks, doneClicks;    final int WRONG_SETTINGS_DIALOG = 0;    final int SET_SETTINGS_DIALOG = 1;    LayoutInflater inflater;    VIEw Failed_login, wrong_settings, card1, card2, set_settings;    button loginbutton, settingsbutton, donebutton, checkServer, yes_button, no_button, ok_button;    ImageVIEw Failed_login_image, wrong_settings_image, set_settings_image;    TextVIEw Failed_login_errorText, wrong_settings_errorText, set_settings_errorText;    Boolean correctSettings;    VIEwFlipper flipper;    Resources res;    Application app;    OutputStreamWriter settings_outstream;    inputStream settings_instream;    Toast Failed_login_errorMessage;    Dialog wrong_settings_errorMessage, set_settings_errorMessage;    Builder test;    /** Called when the activity is first created. */    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        if (savedInstanceState != null)        {            int flipperposition = savedInstanceState.getInt("CARD_NUMBER");            flipper.setdisplayedChild(flipperposition);        }        setContentVIEw(R.layout.login);        context = getApplicationContext();        res = getResources();        app = ((AtriumApplication)this.getApplication());        inflater = getLayoutInflater();        Failed_login = inflater.inflate(R.layout.Failed_login, (VIEwGroup) findVIEwByID(R.ID.Failed_login));        wrong_settings = inflater.inflate(R.layout.wrong_settings, (VIEwGroup) findVIEwByID(R.ID.wrong_settings));        set_settings = inflater.inflate(R.layout.set_settings, (VIEwGroup) findVIEwByID(R.ID.set_settings));        loginbutton = (button)findVIEwByID(R.ID.login);        settingsbutton = (button)findVIEwByID(R.ID.settings);        donebutton = (button)findVIEwByID(R.ID.done);        checkServer = (button)findVIEwByID(R.ID.check_server);        //((button)findVIEwByID(R.ID.login)).setonClickListener(mAddListener);        user = (EditText)findVIEwByID(R.ID.username);        pass = (EditText)findVIEwByID(R.ID.password);        servername = (EditText)findVIEwByID(R.ID.servername);        propertyID = (EditText)findVIEwByID(R.ID.propertyID);        flipper=(VIEwFlipper)findVIEwByID(R.ID.cards);        Failed_login_image = (ImageVIEw) Failed_login.findVIEwByID(R.ID.Failed_login_image);        Failed_login_image.setimageResource(R.drawable.warning2);        Failed_login_errorText = (TextVIEw) Failed_login.findVIEwByID(R.ID.text);        Failed_login_errorText.setText(res.getString(R.string.Failed_login));        Failed_login_errorMessage = new Toast(context);        Failed_login_errorMessage.setGravity(Gravity.CENTER_VERTICAL, 0, 0);        Failed_login_errorMessage.setDuration(Toast.LENGTH_LONG);        Failed_login_errorMessage.setVIEw(Failed_login);        loginbutton.setonClickListener(loginListener);        settingsbutton.setonClickListener(settingsListener);        donebutton.setonClickListener(doneListener);        checkServer.setonClickListener(checkServerListener);        settingsClicks = 0;        doneClicks = 0;        if ((((AtriumApplication)app).getCorrectSettings()))        {            donebutton.getBackground().setcolorFilter(new lightingcolorFilter(0xFF0000FF, 0xFF000010));        }        else        {            donebutton.getBackground().setcolorFilter(new lightingcolorFilter(0xFFFF1010, 0xFFAA0000));            showDialog(SET_SETTINGS_DIALOG);        }    }    @OverrIDe    public voID onSaveInstanceState(Bundle savedInstanceState)    {        int position = flipper.getdisplayedChild();        savedInstanceState.putInt("CARD_NUMBER", position);    }

这是发生错误的地方的Logcat输出:

08-20 11:23:52.730: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.740: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.760: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.770: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.790: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.810: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.820: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.830: INFO/SurfaceFlinger(223): ID=6705 Removed Starting com.szymon.atrium IDx=4 Map Size=508-20 11:23:52.830: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.830: INFO/SurfaceFlinger(223): ID=6705 Removed Starting com.szymon.atrium IDx=-2 Map Size=508-20 11:23:52.840: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.860: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.870: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:52.890: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:23:54.010: DEBUG/HIErarchicalStateMachine(293): handleMessage: E msg.what=8308-20 11:23:54.010: DEBUG/HIErarchicalStateMachine(293): processMsg: ConnectedState08-20 11:23:54.010: DEBUG/WifiStateMachine(293): ConnectedState{ what=83 when=-4ms arg1=936 }08-20 11:23:54.030: DEBUG/HIErarchicalStateMachine(293): handleMessage: X08-20 11:23:57.030: DEBUG/HIErarchicalStateMachine(293): handleMessage: E msg.what=8308-20 11:23:57.030: DEBUG/HIErarchicalStateMachine(293): processMsg: ConnectedState08-20 11:23:57.030: DEBUG/WifiStateMachine(293): ConnectedState{ what=83 when=-4ms arg1=936 }08-20 11:23:57.050: DEBUG/HIErarchicalStateMachine(293): handleMessage: X08-20 11:23:57.480: DEBUG/dalvikvm(30999): GC_EXPliCIT freed 1181K, 30% free 14894K/21255K, paused 3ms+3ms08-20 11:24:00.000: DEBUG/KeyguardUpdateMonitor(293): received broadcast androID.intent.action.TIME_TICK08-20 11:24:00.000: DEBUG/KeyguardUpdateMonitor(293): handleTimeUpdate08-20 11:24:00.050: DEBUG/HIErarchicalStateMachine(293): handleMessage: E msg.what=8308-20 11:24:00.050: DEBUG/HIErarchicalStateMachine(293): processMsg: ConnectedState08-20 11:24:00.050: DEBUG/WifiStateMachine(293): ConnectedState{ what=83 when=-3ms arg1=936 }08-20 11:24:00.070: DEBUG/HIErarchicalStateMachine(293): handleMessage: X08-20 11:24:01.070: INFO/OrIEntationDeBUG(293): [pwm] in MyOrIEntationListener.onorIEntationChanged() rotation=1  mFancyRotationAnimation=0   Now call mWindowManager.setRotation()08-20 11:24:01.070: INFO/OrIEntationDeBUG(293): [wms] in setRotation() rotation=1 alwaysSendConfiguration=false animFlags=008-20 11:24:01.070: INFO/OrIEntationDeBUG(293): [wms] in setRotation() Now call setRotationUnchecked()08-20 11:24:01.070: INFO/OrIEntationDeBUG(293): [pwm] rotationForOrIEntationLw(), orIEntation=-1 lastRotation=2 userRotation=308-20 11:24:01.070: INFO/OrIEntationDeBUG(293): [pwm] useSensorForOrIEntationLp(), return true #208-20 11:24:01.070: INFO/OrIEntationDeBUG(293): [pwm] in rotationForOrIEntationLw(), return #1308-20 11:24:01.070: VERBOSE/WindowOrIEntationListener(293): > OrIEntation changed!  rotation=108-20 11:24:01.070: VERBOSE/WindowOrIEntationListener(293): Result: rotation=1, confIDence=[0.0, 1.0, 0.0, 0.0], timedeltaMS=54.10408-20 11:24:01.240: INFO/SurfaceFlinger(223): ID=6709(1638) createSurface 0x14c93c for pID 0 (1280x800),2 flag=0, FreezeSurface08-20 11:24:01.280: INFO/OrIEntationDeBUG(293): [wms] in setRotationUncheckedLocked(), Setting rotation to 1   The rotation is came from PWM.rotationForOrIEntationLw()08-20 11:24:01.280: DEBUG/SurfaceFlinger(223): mCurrentState.orIEntation:1 mDrawingState.orIEntation:208-20 11:24:01.280: DEBUG/TvoutSystem(293): bool androID::TvoutSystem::TvoutSetRotation(int)08-20 11:24:01.280: DEBUG/TvoutSystem(293): bool androID::TvoutSystem::TvoutGetCableStatus()08-20 11:24:01.280: DEBUG/TvoutService(230): virtual bool androID::TvoutService::TvoutGetCableStatus()08-20 11:24:01.280: DEBUG/TvoutService(Java)(293): TvoutGetCableStatus() : false08-20 11:24:01.280: INFO/WindowManager(293): Setting rotation to 1, animFlags=008-20 11:24:01.280: INFO/ActivityManager(293): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=1/1/2 nav=1/2 orIEn=P layout=0x10000014 uiMode=0x11 seq=291 FlipFont=0}08-20 11:24:01.290: VERBOSE/WindowManager(293): Preventing status bar from hIDing by policy08-20 11:24:01.320: VERBOSE/WindowOrIEntationListener(293): > OrIEntation changed!  rotation=108-20 11:24:01.320: VERBOSE/WindowOrIEntationListener(293): Result: rotation=1, confIDence=[0.0, 1.0, 0.0, 0.0], timedeltaMS=54.10408-20 11:24:01.320: INFO/WindowManager(293): Putting input method here!08-20 11:24:01.320: DEBUG/WindowManager(293):     w.mAttrs.token=ActivityRecord{41811888 com.szymon.atrium/.AtriumMain}08-20 11:24:01.320: DEBUG/WindowManager(293):     w.mToken=AppWindowToken{427877c0  token=ActivityRecord{41811888 com.szymon.atrium/.AtriumMain}}08-20 11:24:01.320: DEBUG/WindowManager(293):     token=AppWindowToken{427877c0 token=ActivityRecord{41811888 com.szymon.atrium/.AtriumMain}}08-20 11:24:01.320: INFO/SurfaceFlinger(223): ID=6707 Removed com.szymon.atrium/com.szymon.atrium.AtriumMain IDx=2 Map Size=508-20 11:24:01.320: INFO/WindowManager(293): Placing input method @508-20 11:24:01.330: INFO/SurfaceFlinger(223): ID=6707 Removed com.szymon.atrium/com.szymon.atrium.AtriumMain IDx=-2 Map Size=508-20 11:24:01.330: ERROR/TelephonyManager(22015): HIDden constructor called more than once per process!08-20 11:24:01.330: INFO/WindowManager(293): Placing input method @108-20 11:24:01.340: DEBUG/MiniModeAppsPanel(430): ACTION_CONfigURATION_CHANGED08-20 11:24:02.140: VERBOSE/WindowOrIEntationListener(293): rotation : 1   Angle: 90   tilt: 208-20 11:24:03.070: DEBUG/HIErarchicalStateMachine(293): handleMessage: E msg.what=8308-20 11:24:03.070: DEBUG/HIErarchicalStateMachine(293): processMsg: ConnectedState08-20 11:24:03.070: DEBUG/WifiStateMachine(293): ConnectedState{ what=83 when=-4ms arg1=936 }08-20 11:24:03.070: DEBUG/HIErarchicalStateMachine(293): handleMessage: X08-20 11:24:03.070: WARN/WindowManager(293): Window freeze timeout expired.08-20 11:24:03.070: WARN/WindowManager(293): Force clearing orIEntation change: Window{407d1208 inputMethod paused=false}08-20 11:24:03.390: WARN/inputConnectionWrapper.ICC(439): Timed out waiting on IinputContextCallback08-20 11:24:03.420: WARN/Resources(439): Converting to boolean: TypedValue{t=0x3/d=0x15 "true" a=-1}08-20 11:24:03.430: WARN/Resources(439): Converting to boolean: TypedValue{t=0x3/d=0x15 "true" a=-1}08-20 11:24:03.590: VERBOSE/WindowOrIEntationListener(293): rotation : 1   Angle: 90   tilt: 008-20 11:24:05.070: VERBOSE/WindowOrIEntationListener(293): rotation : 1   Angle: 90   tilt: -208-20 11:24:05.430: WARN/inputConnectionWrapper.ICC(439): Timed out waiting on IinputContextCallback08-20 11:24:05.450: ERROR/tabletStatusbar(430): closing mini mode apps panel08-20 11:24:05.490: DEBUG/dalvikvm(439): GC_FOR_ALLOC freed 1756K, 38% free 10279K/16391K, paused 27ms08-20 11:24:06.080: DEBUG/HIErarchicalStateMachine(293): handleMessage: E msg.what=8308-20 11:24:06.080: DEBUG/HIErarchicalStateMachine(293): processMsg: ConnectedState08-20 11:24:06.080: DEBUG/WifiStateMachine(293): ConnectedState{ what=83 when=-4ms arg1=936 }08-20 11:24:06.090: DEBUG/HIErarchicalStateMachine(293): handleMessage: X08-20 11:24:06.290: WARN/WindowManager(293): App freeze timeout expired.08-20 11:24:06.290: WARN/WindowManager(293): Force clearing freeze: AppWindowToken{427877c0 token=ActivityRecord{41811888 com.szymon.atrium/.AtriumMain}}08-20 11:24:06.300: INFO/SurfaceFlinger(223): ID=6710(1639) createSurface for pID 0 (800x2560),-1 flag=131072, BlackSurface08-20 11:24:06.300: INFO/SurfaceFlinger(223): ID=6711(1640) createSurface for pID 0 (1600x1280),-1 flag=131072, BlackSurface08-20 11:24:06.300: INFO/SurfaceFlinger(223): ID=6712(1641) createSurface for pID 0 (800x2560),-1 flag=131072, BlackSurface08-20 11:24:06.310: INFO/SurfaceFlinger(223): ID=6713(1642) createSurface for pID 0 (1600x1280),-1 flag=131072, BlackSurface08-20 11:24:06.370: DEBUG/dalvikvm(15392): GC_CONCURRENT freed 458K, 37% free 7282K/11399K, paused 7ms+8ms08-20 11:24:06.370: DEBUG/dalvikvm(20484): GC_EXPliCIT freed 9K, 5% free 6215K/6531K, paused 3ms+2ms08-20 11:24:06.560: VERBOSE/WindowOrIEntationListener(293): rotation : 1   Angle: 90   tilt: -308-20 11:24:06.740: INFO/SurfaceFlinger(223): ID=6709 Removed FreezeSurface IDx=9 Map Size=408-20 11:24:06.740: INFO/SurfaceFlinger(223): ID=6710 Removed BlackSurface IDx=5 Map Size=408-20 11:24:06.740: INFO/SurfaceFlinger(223): ID=6711 Removed BlackSurface IDx=5 Map Size=408-20 11:24:06.750: INFO/SurfaceFlinger(223): ID=6712 Removed BlackSurface IDx=5 Map Size=408-20 11:24:06.750: INFO/SurfaceFlinger(223): ID=6712 Removed BlackSurface IDx=-2 Map Size=408-20 11:24:06.750: INFO/SurfaceFlinger(223): ID=6711 Removed BlackSurface IDx=-2 Map Size=408-20 11:24:06.750: INFO/SurfaceFlinger(223): ID=6710 Removed BlackSurface IDx=-2 Map Size=408-20 11:24:06.750: INFO/SurfaceFlinger(223): ID=6709 Removed FreezeSurface IDx=-2 Map Size=408-20 11:24:06.750: INFO/SurfaceFlinger(223): ID=6713 Removed BlackSurface IDx=5 Map Size=408-20 11:24:06.750: INFO/OrIEntationDeBUG(293): [pwm] rotationForOrIEntationLw(), orIEntation=-1 lastRotation=1 userRotation=308-20 11:24:06.750: INFO/OrIEntationDeBUG(293): [pwm] useSensorForOrIEntationLp(), return true #208-20 11:24:06.750: INFO/OrIEntationDeBUG(293): [pwm] in rotationForOrIEntationLw(), return #1308-20 11:24:06.760: INFO/SurfaceFlinger(223): ID=6713 Removed BlackSurface IDx=-2 Map Size=408-20 11:24:08.030: VERBOSE/WindowOrIEntationListener(293): rotation : 1   Angle: 90   tilt: -308-20 11:24:08.460: DEBUG/dalvikvm(293): GC_EXPliCIT freed 1140K, 16% free 116574K/137223K, paused 13ms+19ms08-20 11:24:09.090: DEBUG/HIErarchicalStateMachine(293): handleMessage: E msg.what=8308-20 11:24:09.090: DEBUG/HIErarchicalStateMachine(293): processMsg: ConnectedState08-20 11:24:09.090: DEBUG/WifiStateMachine(293): ConnectedState{ what=83 when=-4ms arg1=936 }08-20 11:24:09.110: DEBUG/HIErarchicalStateMachine(293): handleMessage: X08-20 11:24:09.500: VERBOSE/WindowOrIEntationListener(293): rotation : 1   Angle: 91   tilt: 208-20 11:24:11.380: DEBUG/dalvikvm(20510): GC_EXPliCIT freed 20K, 5% free 6220K/6531K, paused 2ms+9ms08-20 11:24:12.120: DEBUG/HIErarchicalStateMachine(293): handleMessage: E msg.what=8308-20 11:24:12.120: DEBUG/HIErarchicalStateMachine(293): processMsg: ConnectedState08-20 11:24:12.120: DEBUG/WifiStateMachine(293): ConnectedState{ what=83 when=-4ms arg1=936 }08-20 11:24:12.130: DEBUG/HIErarchicalStateMachine(293): handleMessage: X

我希望这有帮助.

解决方法:

尝试通过覆盖onSaveInstanceState来保存屏幕方向更改时在VIEwFlipper中保存的选项卡

@OverrIDepublic voID onSaveInstanceState(Bundle savedInstanceState) {    int position = flipper.getdisplayedChild();    savedInstanceState.putInt("TAB_NUMBER", position);}

然后在你的onCreate中,尝试以下方法

@OverrIDepublic voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    if (savedInstanceState != null) {        int flipperposition = savedInstanceState.getInt("TAB_NUMBER");        flipper.setdisplayedChild(flipperposition);    }}

确保只在初始化了鳍状肢之后才在鳍状肢上调用setdisplayedChild()方法,例如,通过执行某些 *** 作

flipper =(VIEwFlipper)findVIEwByID(R.ID.flipper);

在你的onCreate()方法中.不这样做可能会导致崩溃.

总结

以上是内存溢出为你收集整理的android – 如何在更改方向时保持ViewFlipper中的当前视图全部内容,希望文章能够帮你解决android – 如何在更改方向时保持ViewFlipper中的当前视图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115343.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存