当我在 Android 中更改屏幕方向时,会调用 Spinner 中的 OnItemSelectedListener。
这不仅仅是模拟器,它也发生在物理手机上。
我怎样才能阻止这种情况发生?
干杯。
当我将屏幕方向从垂直更改为水平然后再次返回时,RecyclerView 会重新绘制并覆盖旧的(您可以在卡片视图之间看到它):
问题:如何抑制这种行为,以便 Android 始终重用最初创建的 RecyclerView?
XML 片段
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:lib="http://schemas.android.com/tools"
android:id="@+id/maschine_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/maschine_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
主要XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/maschineCoordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<include
android:id="@+id/toolbar_main"
layout="@layout/toolbar"></include>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/machinelistcontainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior = "@string/appbar_scrolling_view_behavior"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_cloud_sync_maschinen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_cloud_sync_white_48dp"
app:borderWidth="0dp"
app:elevation="@dimen/fab_elevation"
app:rippleColor="#00ffff"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有几个对话框片段。我想要的是这个:
当一个特定的对话框片段打开并发生旋转时,我想防止该特定片段的屏幕旋转。
另外,我希望其他片段在屏幕旋转时正常运行。
这是我想停止屏幕旋转的对话框片段的java代码:
public class DialogDelete extends DialogFragment implements View.OnClickListener {
TextView textViewNaslov, textViewNote;
ImageView mBtnClose, mBtnReturn, mBtnDelete;
private RealmResults<Drop> mRealmResolts;
private Realm mRealm;
private Calendar calendar;//pravimo objekt kalendara
private BucketPickerView_Unselected mBucketNoteTimeNonSelected; //ovo nam je drugi bucket pickerview kojeg ne mozemo mjenjati
private Bundle argumetns;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogTheme); //dodajemo temu koju smo napravili preko editora
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.dialog_delete, container, …Run Code Online (Sandbox Code Playgroud)android orientation screen-orientation android-dialogfragment dialogfragment
我是 Ionic 4 的新手,我正在尝试将屏幕方向设置为横向并参考文档,这就是我正在做的:
...
import {ScreenOrientation} from '@ionic-native/screen-orientation';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private screenOrientation: ScreenOrientation,
) {
this.initializeApp();
}
initializeApp() {
this.screenOrientation.lock(ScreenOrientation.ORIENTATIONS.LANDSCAPE);
...
}
}
Run Code Online (Sandbox Code Playgroud)
在编译期间,我收到此错误:
[ng] src/app/app.component.ts(24,33) 中的错误:错误 TS2345:“字符串”类型的参数不可分配给“OrientationLockType”类型的参数。
并在浏览器控制台上:
未捕获的错误:无法解析 AppComponent 的所有参数:([object Object], [object Object], [object Object], ?)。在语法错误 (compiler.js:2426) [] ...
当我更改模拟器或手机上的方向时,片段会额外加载一次。如果我将设备旋转 3 次,则片段将在最后一次旋转后加载 3 次;如果我将设备旋转 5 次,则片段将在最后一次旋转后加载 5 次。
主要活动
...
FragmentOne fragment = new FragmentOne();
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.main_container, fragmnet);
transaction.commit();
Run Code Online (Sandbox Code Playgroud)
我在片段中唯一拥有的就是日志,没有任何东西会导致片段多次加载。片段一
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
Log.d(TAG, "onCreateView: ");
return inflater.inflate(R.layout.fragment_fragment_one, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Log.d(TAG, "onViewCreated: ");
}
Run Code Online (Sandbox Code Playgroud)
这是一次旋转后的日志副本,请注意 onCreateView 在一次方向更改时被多次调用。
2020-04-13 01:23:07.396 10857-10857/com.example.myapplication D/MYFragmentOne: onCreate:
2020-04-13 01:23:07.396 10857-10857/com.example.myapplication …Run Code Online (Sandbox Code Playgroud) 我有调用的布局,Main.XML我将方向设置为我的肖像AndroidManifest.xml.我设计了这个布局蜂窝太大,并把它放在在layout-xlarge-mdpi文件夹中,但我想使用 Main.XML在layout-xlarge-mdpi只在横向方向.
现在,怎么办呢?
谢谢
我正在使用XNA(使用DirectX)进行一些图形编程.我有一个围绕一个点旋转的盒子,但旋转有点奇怪.
一切似乎有人拿了一个指南针并旋转180度,所以N是180,W是90等.
我似乎找不到一个说明方向的来源,所以我可能只是没有使用正确的关键字.
有人可以帮我找到XNA/DirectX的定位,以及一个说明这一点的页面吗?
在此应用程序中启动纵向模式.

.
代码段
NSInteger heightOne;
NSInteger heightTwo;
NSInteger imgV;
CGRect Bounds = [[UIScreen mainScreen] bounds];
if (Bounds.size.height == 568) {
// code for 4-inch screen
heightOne = 480+38;
heightTwo = 240+38;//370
imgV = 360;
} else {
// code for 3.5-inch screen
heightOne = 480;
heightTwo = 240;//330
imgV = 310;
}
UIView *firstView = [[UIView alloc] initWithFrame:CGRectMake(00, 00,320,heightOne)];
firstView.opaque = NO;
firstView.tag = 1000;
firstView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
[self.view addSubview:firstView];
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(250,imgV,50,50)];
img.image = [UIImage …Run Code Online (Sandbox Code Playgroud) 我有一个带故事板的iOS应用程序.我希望我的上一个viewcontroller始终处于纵向模式.我一直在读书,从那以后我发现了
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
Run Code Online (Sandbox Code Playgroud)
不推荐使用我应该使用其他方法
-(BOOL)shouldAutorotate
-(NSInteger)supportedInterfaceOrientations
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
Run Code Online (Sandbox Code Playgroud)
但我已经尝试了很多这种方法的组合,我无法做到这一点.所以请有人能告诉我正确的方法吗?
我有一个多次初始化的活动(片段,共享偏好,服务,ui组件(搜索栏,按钮等)...)我不想在屏幕方向改变时重新启动活动
我找到了一个简单(和工作的解决方案),android:configChanges="keyboardHidden|orientation|screenSize"但我的技术经理以这种方式禁止我,因为据他说这是一个不好的做法
为了正确处理屏幕方向变化,还有哪些其他方法?
非常感谢你
我的主要活动
@AfterViews
public void afterViews() {
putSharedPrefs();
initializeFragments();
initializeComponents();
initializeSynchronizeDialog();
initDownloadDialog();
}
Run Code Online (Sandbox Code Playgroud) 我查看了人们提出的其他问题,但我不确定解决此问题的最佳方法是什么。通过 Android 的指南实现相机后,我拥有的相机预览被锁定为横向。我想知道如何调整相机方向以反映手机的方向。
我试过这个
camera.setDisplayOrientation(90);
Run Code Online (Sandbox Code Playgroud)
并且将相机锁定为纵向模式,因此我需要另一种解决方案(最好是适用于大多数设备的解决方案)。
另外,我怎样才能使保存的图像以与预览相同的方式显示?现在,如果我使用上面的那行代码使预览转到纵向,则保存的图像仍会旋转为横向。