标签: screen-rotation

如何检测屏幕旋转

我有一个显示指南针的活动,我需要知道屏幕的方向以正确旋转针.我需要区分90°和270°旋转才能正确处理.

当我旋转屏幕(至少在我的Nexus S上)时,onCreate会调用活动,例如当我从纵向模式旋转到横向模式时.当我从一个横向模式旋转到另一个横向边缘凸起时,onCreate()会被调用两次(一次用于纵向,一次用于目标横向模式).

但是,当我以底边向上旋转时,屏幕旋转180°并且onCreate不会被调用.在这种情况下会有被触发的事件吗?

android screen-rotation

15
推荐指数
2
解决办法
5万
查看次数

检测iOS中的旋转更改

我正在制作一个iOS应用程序,需要在旋转时进行一些界面重新排列.我试图通过实现检测到这一点- (void)orientationChanged:(NSNotification *)note,但这会给我通知设备面朝上或面朝下的时间.

我想要一种方法来在界面改变方向时得到通知.

interface nsnotificationcenter screen-rotation ios auto-rotation

15
推荐指数
4
解决办法
2万
查看次数

在片段中使用onConfigurationChanged

我在片段中有这个代码

public class TestOne extends Fragment {

    View view = null;

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);

      LayoutInflater inflater2 = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater2.inflate(R.layout.testone, null); 

        Toast.makeText(getActivity(), "Rotate fragment", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Toast.makeText(getActivity(), "onCreate Fragment", Toast.LENGTH_SHORT).show();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.testone, null); 

        Toast.makeText(getActivity(), "onCreateView fragment", Toast.LENGTH_SHORT).show();

        return view; 
    }

}
Run Code Online (Sandbox Code Playgroud)

我想要做的是,当我旋转手机时,我不希望再次执行这些方法.但我想再次调用xml布局,以加载layout-land文件夹的xml.

这段代码不会给出任何错误,只是不起作用而且不明白原因..

我真的很想使用onConfiguratonChanged来做这件事

我感谢任何帮助.

感谢致敬

android onconfigurationchanged screen-rotation android-fragments

14
推荐指数
1
解决办法
2万
查看次数

隐藏的backstack片段在配置更改时重新显示

我正在构建一个活动多片段应用程序.每次交易后我都会添加到backstack.在几次隐藏和显示片段然后我旋转手机之后,容器上添加的所有片段都被恢复,每个片段都在另一个片段之上.

可能是什么问题?为什么我的活动会显示我之前隐藏的片段?

我正在考虑隐藏所有以前隐藏的现在显示的片段,但是有更"优雅"的方式吗?

android screen-rotation android-fragments

13
推荐指数
2
解决办法
2336
查看次数

如何将帧坐标映射到视觉中的叠加

我觉得这个问题已经解决了很多次,但我无法弄清楚.我基本上遵循了关于移动视觉的这个小教程并完成了它.之后我尝试从ColorBlob开始检测对象并绘制边框.

想法是从框架的中间开始(有目的地将对象保持在相机的中间)并通过其颜色检测该对象的边缘.只要我以横向模式(Frame.ROTATION_0)保持手机,它就可以正常工作.一旦我处于纵向模式(Frame.Rotation_90),边界Rect就会被绘制成旋转,因此具有更多高度的对象将被绘制为具有更多宽度,并且还有点偏离.

文档说,探测器总是提供给COORDS未旋转直立框架,所以我怎么来计算相对于它的旋转边框COORDS?我认为这不重要,但这是我如何找到颜色Rect

public Rect getBounds(Frame frame){
  int w = frame.getMetadata().getWidth();
  int h = frame.getMetadata().getHeight();
  int scale = 50;
  int scaleX = w / scale;
  int scaleY = h / scale;
  int midX = w / 2;
  int midY = h / 2;
  float ratio = 10.0
  Rect mBoundary = new Rect();
  float[] hsv = new float[3];
  Bitmap bmp = frame.getBitmap();
  int px = bmp.getPixel(midX, midY);
  Color.colorToHSV(px, hsv);
  Log.d(TAG, "detect: mid hsv: " + hsv[0] …
Run Code Online (Sandbox Code Playgroud)

camera android drawing screen-rotation android-vision

13
推荐指数
0
解决办法
445
查看次数

如何在android中防止设备轮换的冲突动画?

我在活动中有一个两个按钮对象这个对象有一些动画与ObjectAnimator这些动画工作完美但当动画在背景中运行时我想旋转设备有时在ObjectAnimator中纵向模式坐标以横向模式或反向运行.

ObjectAnimator move_next_btn = ObjectAnimator.ofFloat(next_btn, "x", next_btn.getX(),
                        next_btn.getX() + next_btn.getWidth());
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,按钮应该离开屏幕,但是在此行之后,如果设备旋转到横向模式按钮进入中间屏幕,我认为当出现此问题时,纵向坐标在横向模式下运行.

我在图片中给出了更多细节:

  1. 这是我的图片查看器,当用户没有触摸屏幕按钮时,侧面有两个按钮,屏幕上出现了动画:

在此输入图像描述

  1. 第二个图像显示其中一个箭头是隐藏(也许)我认为这是因为当动画想要运行时我旋转屏幕并且箭头保持在屏幕外:

在此输入图像描述

  1. 在第三张图像中,当动画以纵向模式运行时,我旋转到横向模式,箭头停留在屏幕中央,当然,如果再次旋转到横向箭头,此图像将进入纵向模式:

在此输入图像描述

这恰好发生在移动动画(int代码上方)和屏幕旋转同时运行时并不总是这样.

完整代码:

private void init() {
        index = getIntent().getIntExtra("index", 0);
        current_index = getIntent().getIntExtra("current_index", 0);

        final View previous_btn_rl = findViewById(R.id.previous_btn_rl);
        findViewById(R.id.previous_btn_rl).findViewById(R.id.previous_btn)
                .setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                time_to_hide_button = 3;
                try {
                    AssetManager assetManager = getAssets();
                    if (current_index > 0) {
                        current_index--;
                        String path = "img" + "/" + String.valueOf(index + 1) + "/gallery/" + String.valueOf(current_index + 1) + ".jpg";
                        imageView.setImageBitmap(BitmapFactory.decodeStream(assetManager.open(path)));
                    }
                } …
Run Code Online (Sandbox Code Playgroud)

java android android-animation screen-rotation

13
推荐指数
1
解决办法
627
查看次数

在哪里更改"已安装"以进行自动布局约束?

在故事板中使用自动布局时,可以选择是否使用"已安装"复选框来安装约束.禁用它将导致它表现得就像你没有添加该约束 - 它将没有任何效果.您可以在Interface Builder中为不同大小的类配置已安装的状态,并且可以通过将其active属性设置为true或以编程方式更改此值false.

在我的应用程序中,我希望仅在设备处于纵向时安装约束 - 旋转到横向时应该"卸载".通过取消选中为任意宽度紧凑高度安装,可以为iPhone完成此操作.(虽然这似乎不太正常,因为当它甚至不应该安装时,由于在转向横向时出现冲突的约束而破坏了这个约束,但是无论UI总是按预期出现.)但是没有办法卸载Interface Builder中的横向iPad约束(两个方向的常规宽度常规高度).

哪里是合适的地方来启用/禁用activeNSLayoutConstraint轮值设备时?在什么轮换方法将改变该状态导致所需的行为 - 只安装为肖像?如果在启动应用程序时没有调用该方法,除了旋转方法之外还应该放置哪种方法?

我已尝试将以下代码放入其中viewDidLoad,viewWillTransitionToSize但这会导致在iPad上运行时出现一些意外行为:

  • 以横向方式启动应用程序会导致约束处于活动状态,尽管事件active设置为false,它会破坏约束,并且UI不会按预期显示
  • 以纵向方式启动应用程序将活动设置为true(它已经安装在IB中),因此它按预期工作
  • 以纵向方式启动应用程序并将设备旋转到横向按预期工作 - 约束设置为非活动状态,它不会破坏约束,UI显示为预期
  • 以纵向方式启动应用程序,旋转到横向以及返回到纵向会导致UI显示正确,但它会破坏设置为活动的此约束

如果我在Interface Builder中卸载约束然后运行上面的场景我基本上会得到相反的行为.

if size.width > size.height {
    self.myConstraint.active = false
} else {
    self.myConstraint.active = true
}
Run Code Online (Sandbox Code Playgroud)

screen-rotation ios autolayout nsautolayout ios8

11
推荐指数
1
解决办法
3899
查看次数

如何在 SwiftUI 中禁用设备旋转动画?

对于 UIKit 禁用设备旋转动画,您可以重写 viewWillTransitionToSize 方法。 禁用方向改变旋转动画 但是在 SwiftUI 中实现这一点的最佳方法是什么?

animation screen-rotation ios swiftui

11
推荐指数
1
解决办法
1118
查看次数

旋转回肖像时,避免Android VideoView损坏

我设法写了一个有限的视频播放器,能够从互联网上查看.3gp文件.视频将以全屏显示,保持视频宽高比.此外,旋转不会中断视频,从而保持播放没有问题.

一切似乎都很好,但是......当你旋转回到肖像时,我的HTC图例中,视频已损坏,而不是显示全屏,它以原始像素大小显示.但再次旋转到景观作品,并完美展现.有什么想法吗?不幸的是,我没有更多的硬件来测试它,我已经用尽了测试的想法.

您可以从https://github.com/gradha/Android-video-stream-rotation获取完整的示例源代码.以下是我打开应用程序,旋转到横向,触摸屏幕以显示视频控件,然后旋转回到肖像以查看损坏的屏幕截图. 视频开始画像正常

在风景上视频也很好用

但现在回到肖像总是显示腐败

android corruption screen-rotation android-videoview

10
推荐指数
1
解决办法
8903
查看次数

屏幕旋转后Android片段重叠

这个应用程序是我使用碎片等学习练习.它有一个活动来管理一些不同的片段.第一个是ListFragment(A),它显示应用程序何时启动并从游标加载列表项.单击列表项会通知活动将ListFragment替换为该项目的DetailFragment(B).如果在看(B)的同时旋转屏幕,我会看到(B)在(A)之上,如下所示:

http://postimage.org/image/uhy016ds7/

我最好的猜测是它与Android销毁和重新创建配置更改活动有关.我想知道什么是这个问题最干净的解决方案.下面是一些代码片段,请告诉我是否应该发布其他内容.

RES /布局/ home.xml

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

    <fragment
        android:id="@+id/fragment_place_list"
        android:name="com.simbiosys.apps.foodfast.ui.PlaceListFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </fragment>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

MyActivity.onCreate

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    placeListFragment = (PlaceListFragment) getSupportFragmentManager().findFragmentById(
            R.id.fragment_place_list);

}
Run Code Online (Sandbox Code Playgroud)

MyActivity.showDetailPane

public void showDetailPane(String id, String reference) {
    placeDetailFragment = PlaceDetailFragment.newInstance(id, reference);
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.addToBackStack(null);
    ft.hide(placeListFragment);
    ft.replace(R.id.fragment_container, placeDetailFragment);
    ft.show(placeDetailFragment);
    ft.commit();
}
Run Code Online (Sandbox Code Playgroud)

android fragment screen-rotation overlapping

10
推荐指数
3
解决办法
8011
查看次数