繁体   English   中英

Android布局XML旋转方向

[英]Android layout xml rotation orientation

我正在转换入门版Android示例Camera2Video示例: https : //github.com/googlesamples/android-Camera2Video

单独运行示例时,旋转效果很好,并且控件始终可见。 但是,当我在Cordova插件中嵌入相同的代码时,旋转时控件消失。

这是布局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>

这是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>

还有用于检测旋转的代码。

我敢肯定这是一个简单的解决方法,我只是想不通!

我完整的插件代码: https : //github.com/kmturley/cordova-plugin-media-custom

我使用以下代码解决了这个问题:

布局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>

布局景观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>

您可以在这里查看它在我的cordova插件上的运行情况:

https://github.com/kmturley/cordova-plugin-media-custom

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM