[英]Android layout xml rotation orientation
I am converting the starter Android sample Camera2Video example: https://github.com/googlesamples/android-Camera2Video 我正在转换入门版Android示例Camera2Video示例: https : //github.com/googlesamples/android-Camera2Video
When running the example by itself the rotation works well, and the controls are always visible. 单独运行示例时,旋转效果很好,并且控件始终可见。 However when I embed the same code inside a Cordova plugin, the controls dissapear when rotated.
但是,当我在Cordova插件中嵌入相同的代码时,旋转时控件消失。
Here is the layout xml: 这是布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.android.camera2video.AutoFitTextureView
android:id="@+id/texture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_below="@id/texture"
android:background="#4285f4">
<ImageButton
android:id="@+id/video"
style="@android:style/Widget.Material.Light.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="Record"
android:padding="20dp"
android:src="@drawable/record" />
<ImageButton
android:id="@+id/info"
android:contentDescription="Info"
style="@android:style/Widget.Material.Light.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:padding="20dp"
android:src="@drawable/gallery" />
</FrameLayout>
</RelativeLayout>
And here is the layout-land xml file 这是layout-land xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.android.camera2video.AutoFitTextureView
android:id="@+id/texture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_below="@id/texture"
android:layout_toRightOf="@id/texture"
android:background="#4285f4"
android:orientation="horizontal">
<ImageButton
android:id="@+id/video"
style="@android:style/Widget.Material.Light.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="Record"
android:padding="20dp"
android:src="@drawable/record" />
<ImageButton
android:id="@+id/info"
style="@android:style/Widget.Material.Light.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:contentDescription="Info"
android:padding="20dp"
android:src="@drawable/gallery" />
</FrameLayout>
</RelativeLayout>
Also there is code to detect the rotation. 还有用于检测旋转的代码。
I'm sure it's a simple fix, I just can't figure it out! 我敢肯定这是一个简单的解决方法,我只是想不通!
My full plugin code: https://github.com/kmturley/cordova-plugin-media-custom 我完整的插件代码: https : //github.com/kmturley/cordova-plugin-media-custom
I solved this using the following code: 我使用以下代码解决了这个问题:
layout xml 布局xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextureView
android:id="@+id/texture"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#66000000"
android:orientation="vertical">
<ImageButton
android:id="@+id/video"
style="@android:style/Widget.Material.Light.Button.Borderless"
android:layout_gravity="center"
android:contentDescription="Record"
android:padding="20dp"
android:src="@drawable/record"
android:layout_width="90dp"
android:layout_height="90dp"
android:scaleType="fitXY" />
<ImageButton
android:id="@+id/info"
android:contentDescription="Info"
style="@android:style/Widget.Material.Light.Button.Borderless"
android:layout_gravity="center_vertical|right"
android:padding="20dp"
android:src="@drawable/gallery"
android:layout_width="90dp"
android:layout_height="90dp"
android:scaleType="fitXY" />
</FrameLayout>
</RelativeLayout>
layout landscape xml 布局景观xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextureView
android:id="@+id/texture"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="#66000000"
android:orientation="horizontal">
<ImageButton
android:id="@+id/video"
style="@android:style/Widget.Material.Light.Button.Borderless"
android:layout_gravity="center"
android:contentDescription="Record"
android:padding="20dp"
android:src="@drawable/record"
android:layout_width="90dp"
android:layout_height="90dp"
android:scaleType="fitXY" />
<ImageButton
android:id="@+id/info"
android:contentDescription="Info"
style="@android:style/Widget.Material.Light.Button.Borderless"
android:layout_gravity="center_horizontal|bottom"
android:padding="20dp"
android:src="@drawable/gallery"
android:layout_width="90dp"
android:layout_height="90dp"
android:scaleType="fitXY" />
</FrameLayout>
</RelativeLayout>
You can see it working on my cordova plugin here: 您可以在这里查看它在我的cordova插件上的运行情况:
https://github.com/kmturley/cordova-plugin-media-custom https://github.com/kmturley/cordova-plugin-media-custom
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.