【问题标题】:Android layout xml rotation orientationAndroid布局xml旋转方向
【发布时间】:2015-08-13 12:13:20
【问题描述】:

我正在转换入门 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

【问题讨论】:

    标签: java android xml cordova layout


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多