我的选项卡式应用不会通过方向更改重新显示视图.
我补充道
android:configChanges="keyboardHidden|orientation"
Run Code Online (Sandbox Code Playgroud)
到主标签活动和清单中的每个活动.
我在每个活动中添加了这个方法:
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.active_alt);
mColorLegendBtn = (Button) findViewById(R.id.colorbtn);
mStatusView = (TextView) findViewById(R.id.celltitle1);
TextView mStatusView1 = (TextView) findViewById(R.id.celltitle2);
mStatusView1.setText(mStatusView1.getText()+"testcase1");
mStatusView.setText(mStatusView.getText()+"testcase");
initUI();
}
public void initUI() {
l1 = (ListView) findViewById(R.id.ListView01);
EfficientAdapter efficientAdapter = new EfficientAdapter(mContext);
l1.setAdapter(null);
l1.setAdapter(efficientAdapter);
}
Run Code Online (Sandbox Code Playgroud)
启动时,正确显示选项卡,列表,按钮和文本视图.当我在模拟器中更改方向时,只显示选项卡,而不显示其他任何小部件,屏幕为黑色.
我错过了什么?
我有一个活动,其中有一个旋转器.因为对于纵向和横向模式,我有不同的布局,所以我在onConfigurationChanged方法中改变布局
@Override
public void onConfigurationChanged(Configuration conf) {
super.onConfigurationChanged(conf);
setContentView(R.layout.layout);
initUI();
}
Run Code Online (Sandbox Code Playgroud)
但问题是当我改变方向时,我的微调器被重新创建,所以如果微调器在纵向模式下打开它在横向模式下接近.我的要求是:如果它在任何模式下打开,它应该在方向改变后打开.你可以请让我知道如何处理这种情况.
我有一个Activity开始并绑定到的Service。然后Activity,我从另一个启动另一个。Activity从第二个返回第一个后,我需要调用Service(保存一些数据)的方法。
在查看每种屏幕时,只要退出之前我返回相同的屏幕方向Activity,我的Activity生命周期方法似乎就足以应对屏幕方向的更改Activity。
当我以离开我的方向不同的方式返回到第一个活动时,就会发生问题。如果发生这种情况,我将失去对自己的引用Service,因此会遇到NullPointerExceptionin onActivityResult()。因此,如果我Activity在人像模式下启动第二个,在查看第二个时切换到风景,而在风景模式下Activity返回第一个Activity,则会崩溃。
我可能会缺少什么?我不想使用清单文件来表示我将处理配置更改-使我感到有些丑陋,无法解决主要问题。除非我再次错过任何东西...
以下是我第一个练习中生命周期方法的摘录:
@Override
protected void onStart()
{
super.onStart();
// start and bind to service
startService(smsIntent);
connection = new SMServiceConnection();
bindService(smsIntent, connection, Context.BIND_AUTO_CREATE);
}
@Override
protected void onRestart()
{
super.onRestart();
}
@Override
protected void onResume()
{
super.onResume();
}
@Override
protected void onPause()
{
super.onPause();
sms.save(); // autosave
}
@Override
protected …Run Code Online (Sandbox Code Playgroud) 我需要获取WebView的宽度和高度,并将它们传递到要在WebView中加载的URL的查询字符串中。我在onResume()中找到了一种方法。由于此时尚未计算宽度和高度,因此我在UI加载后将Runnable发布到要排队的WebView中。
这是我的问题:当方向更改时,我在onConfigurationChanged中处理它。当我尝试在onConfigurationChanged中将Runnable发布到WebView时,WebView的宽度和高度最终是旧方向的宽度和高度。方向更改后,在什么时候可以截取新的宽度和高度?
android width orientation screen-orientation onconfigurationchanged
通常将设备旋转90度(纵向到横向或反向)会导致配置更改,活动被破坏并重新创建等,因此它可以Display.getRotation()在开始时保存值并使用它.
但是,当设备直接从0到180(纵向到纵向)或90到270(横向到横向)旋转时,不会进行任何配置更改,设备只需重新映射屏幕.这是有道理的,因为布局的纵横比不会改变,也不需要改变.但这使得Activity无法检测何时发生这种变化,即何时Surface.ROTATION_90进入Surface.ROTATION_270等等.
除了民意调查Display.getRotation(),有没有更好的方法来检测这种变化?
我们的相机拍摄需要大约10-15秒(由于自定义相机硬件).我需要的是在10-15秒的这个过程中,我不希望用户改变屏幕方向.
我已将takepicture调用放在Async任务的doInBackground中.
在我放置的onPreExecute()方法中
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
在onPostExecute我放了
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
Run Code Online (Sandbox Code Playgroud)
此解决方案对我不起作用,导致相机和设备崩溃,我不得不重新启动设备.
android screen-orientation cameracapturetask android-4.2-jelly-bean
我想有条件地改变用户在我要创建的照片库网站上看到的内容,具体取决于用于查看网站的设备是纵向/垂直还是横向/水平模式/方向.这可能吗?
javascript jquery screen-orientation jquery-mobile landscape-portrait
我正在开发一个Android应用程序,在那里我用点击替换片段.我有横向和纵向模式的单独设计.但问题是,当我改变方向时,活动刷新并且按钮保持未被点击,我尝试给予
android:configChanges="orientation|keyboardHidden"
Run Code Online (Sandbox Code Playgroud)
但没有用,将其设置为屏幕化并没有采用其他布局设计,请建议如何克服这一点,不要刷新方向更改的活动,但仍然接受其他布局.
我有一个非常类似的问题:Android - ActionBar没有使用onConfigurationChanged(AppCompat)调整大小
我需要让android处理方向更改,因为我想重新创建活动.
但是,我还需要检测何时产生了方向变化.
这两项综合需求是否能够立即实现?
android screen-orientation oncreate android-lifecycle android-orientation
我有一个Base活动(extends AppCompactActivity),它被所有活动扩展.我的问题是,如果我android:screenOrientation="portrait"从Manifest文件设置到基本活动,为什么不设置为扩展此活动的所有活动.这是我的清单文件
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BaseActivity"
android:screenOrientation="portrait"/>
<activity android:name=".OtpActivity"></activity>
</application>
Run Code Online (Sandbox Code Playgroud)