从纵向模式更改为横向模式时,活动重新启动

时间:2015-10-21 11:41:29

标签: java android xml android-layout

我为我的活动构建了两个XML文件。一个在布局文件夹中,另一个在layout-land文件夹中。但是当我将方向从纵向模式更改为横向模式时,活动会重新启动。这正是我不想要的。 因为我在三个图表中绘制实时数据,并且当我转动屏幕而不是被中断或以任何方式开始新的时候,绘图应该继续。

这是layout-land文件夹中的第一个XML文件:

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 

 >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="496dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/my_layout" >

<com.jjoe64.graphview.GraphView
    android:id="@+id/sensor1_graph_Feuchtigkeit"
    android:layout_width="match_parent"
    android:layout_height="270dp"
    android:layout_alignLeft="@+id/sensor1_graph_Druck"
    android:layout_alignParentTop="true" />

<com.jjoe64.graphview.GraphView
    android:id="@+id/sensor1_graph_Temperatur"
    android:layout_width="match_parent"
    android:layout_height="270dp"
    android:layout_alignLeft="@+id/sensor1_graph_Feuchtigkeit"
    android:layout_below="@+id/sensor1_graph_Feuchtigkeit"
    android:layout_marginTop="8dp" />

<com.jjoe64.graphview.GraphView
    android:id="@+id/sensor1_graph_Druck"
    android:layout_width="match_parent"
    android:layout_height="270dp"
    android:layout_below="@+id/sensor1_graph_Temperatur"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="8dp" />

<Switch
    android:id="@+id/mySwitch"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_below="@+id/sensor1_graph_Druck"
    android:layout_centerHorizontal="false"
    android:layout_marginTop="8dp"
     />

<TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/switchStatus"
    android:layout_alignParentBottom="true"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/switchStatus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/mySwitch"
    android:layout_alignBottom="@+id/mySwitch"
    android:layout_marginLeft="15dp"
    android:layout_toRightOf="@+id/mySwitch"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<Switch
    android:id="@+id/switch1"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_alignLeft="@+id/mySwitch"
    android:layout_alignParentBottom="true"
     />

    </RelativeLayout>

    </ScrollView>

这里是布局文件夹中的第二个:

 <?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 

 >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="496dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/my_layout" >

<com.jjoe64.graphview.GraphView
    android:id="@+id/sensor1_graph_Feuchtigkeit"
    android:layout_width="match_parent"
    android:layout_height="130dp"
    android:layout_alignLeft="@+id/sensor1_graph_Druck"
    android:layout_alignParentTop="true" />

<com.jjoe64.graphview.GraphView
    android:id="@+id/sensor1_graph_Temperatur"
    android:layout_width="match_parent"
    android:layout_height="130dp"
    android:layout_alignLeft="@+id/sensor1_graph_Feuchtigkeit"
    android:layout_below="@+id/sensor1_graph_Feuchtigkeit"
    android:layout_marginTop="8dp" />

<com.jjoe64.graphview.GraphView
    android:id="@+id/sensor1_graph_Druck"
    android:layout_width="match_parent"
    android:layout_height="130dp"
    android:layout_below="@+id/sensor1_graph_Temperatur"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="8dp" />

<Switch
    android:id="@+id/mySwitch"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_below="@+id/sensor1_graph_Druck"
    android:layout_centerHorizontal="false"
    android:layout_marginTop="8dp"
     />

<TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/switchStatus"
    android:layout_alignParentBottom="true"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/switchStatus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/mySwitch"
    android:layout_alignBottom="@+id/mySwitch"
    android:layout_marginLeft="15dp"
    android:layout_toRightOf="@+id/mySwitch"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<Switch
    android:id="@+id/switch1"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_alignLeft="@+id/mySwitch"
    android:layout_alignParentBottom="true"
     />

    </RelativeLayout>

    </ScrollView>

在Manifest XML中,它看起来像这样:

 <activity
        android:name="com.TomKun.testgraph.DruckActivity"
        android:label="@string/Sensor_1"
        android:launchMode="singleTask"
           android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
    </activity>

如果我有这样的清单

android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
        </activity>

当我从纵向模式切换到横向模式时,布局不会改变。但活动不会重新启动。这是一件好事

但如果我不使用

android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
        </activity>

布局会根据需要更改,但活动会重新启动。

因此,我的实施中的某些内容并不匹配。

任何人都可以帮我解决这个问题吗?

我已经看到很多人在stackoverflow上有类似的问题。但有了这些答案,我无法解决我的问题

提前致谢!

0 个答案:

没有答案
相关问题