Android 开始有关方向更改的新活动
当方向从potrait更改为我正在使用的景观时,我想加载一个新活动:Android 开始有关方向更改的新活动,android,orientation,screen-orientation,Android,Orientation,Screen Orientation,当方向从potrait更改为我正在使用的景观时,我想加载一个新活动: @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { startActivity(
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
startActivity(new Intent(this, ABCDActivity.class));
}
if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
{
super.onConfigurationChanged(newConfig);
finish();
}
}
但它不会随着方向的改变而改变我的活动。我错过了什么吗?当你的方向改变时,为什么要开始一项新的活动? 最好只是为不同的配置提供不同的资源!或者在1活动中使用片段 更多信息可在此处找到:
configChanges=“screenSize…”
。
在活动的xml文件中,您可以链接到另一个片段。
同样,有关这方面的更多信息可以在上面的链接中找到
MyActivity.java
public class MyActivity extends Activity
{
@Override
public void onCreate(Bundle cycle)
{
super.onCreate(cycle);
this.setContentView(R.layout.myactivity);
}
}
res/layout/myactivity.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.example.myapp.fragments.TimeFrameGraphFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.example.myapp.fragments.AllDataGraphFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
和res/layout land/myactivity.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.example.myapp.fragments.TimeFrameGraphFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.example.myapp.fragments.AllDataGraphFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
当您的方向发生变化时,为什么要开始新的活动? 最好只是为不同的配置提供不同的资源!或者在1活动中使用片段 更多信息可在此处找到:
configChanges=“screenSize…”
。
在活动的xml文件中,您可以链接到另一个片段。
同样,有关这方面的更多信息可以在上面的链接中找到
MyActivity.java
public class MyActivity extends Activity
{
@Override
public void onCreate(Bundle cycle)
{
super.onCreate(cycle);
this.setContentView(R.layout.myactivity);
}
}
res/layout/myactivity.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.example.myapp.fragments.TimeFrameGraphFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.example.myapp.fragments.AllDataGraphFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
和res/layout land/myactivity.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.example.myapp.fragments.TimeFrameGraphFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.example.myapp.fragments.AllDataGraphFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
在您的
清单
活动
标记中,对于您希望为其配置更改的每个活动,必须放置以下行:
android:configChanges=“方向|屏幕大小”
作为应用程序设计说明。。。不建议在方向更改时启动新活动…在您的
清单活动
标记中,对于您希望配置更改的每个活动,您必须放置以下行:
android:configChanges=“方向|屏幕大小”
作为应用程序设计说明。。。不建议在方向更改时启动新活动…除非您在AndroidManifest.xml中声明了相应的属性,否则不会调用onConfigurationChanged()方法:
android:configChanges="orientation"
除非在AndroidManifest.xml中声明了相应的属性,否则不会调用onConfigurationChanged()方法:
android:configChanges="orientation"
试试这个
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
startActivity(new Intent(this, ABCDActivity.class));
}
}
试试这个
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
startActivity(new Intent(this, ABCDActivity.class));
}
}
参考此链接-参考此链接-我在纵向模式下显示特定时间间隔的数据(在图形中),但我希望在用户切换到横向模式时显示所有数据。对于使用布局/和布局土地/文件夹的内置资源系统来说,这听起来是一项完美的工作。我用一些示例代码更新了我的答案。如果对您有帮助,请接受。我在纵向模式下显示特定时间间隔的数据(在图形中),但我希望在用户切换到横向时显示所有数据。对于使用布局/和布局/文件夹的内置资源系统来说,这听起来是一个完美的工作。我用一些示例代码更新了我的答案。如果这对你有帮助,请接受它。