Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 横向和纵向定向模式问题_Android_Orientation Changes - Fatal编程技术网

Android 横向和纵向定向模式问题

Android 横向和纵向定向模式问题,android,orientation-changes,Android,Orientation Changes,我正在运行一个应用程序,在该应用程序中,当单击图像时,我正在运行一个音频,当播放音频时,我将模式从横向更改为纵向,或从纵向更改为横向,然后单击图像,它将播放另一个音频剪辑 例如: 现在正在播放2个音频。但在相同模式下单击图像不会出现此问题 当模式更改时,是否有任何方法停止上一个活动?将此代码添加到您面临问题的当前活动中,但这将停止您的应用程序在更改方向时的更改,它将使用当前方向作为两种模式的静态方向,但仍请尝试让我知道 <activity android:name=".CurrentAct

我正在运行一个应用程序,在该应用程序中,当单击图像时,我正在运行一个音频,当播放音频时,我将模式从横向更改为纵向,或从纵向更改为横向,然后单击图像,它将播放另一个音频剪辑

例如:

现在正在播放2个音频。但在相同模式下单击图像不会出现此问题


当模式更改时,是否有任何方法停止上一个活动?

将此代码添加到您面临问题的当前活动中,但这将停止您的应用程序在更改方向时的更改,它将使用当前方向作为两种模式的静态方向,但仍请尝试让我知道

<activity android:name=".CurrentActivity
 android:configChanges="keyboardHidden|orientation">
        </activity>

播放音频文件只需使用服务不要在活动中播放,这样您就可以停止服务,这样歌曲就可以停止播放了。然后你应该专注于如何处理你的定位

  • 再造活动
  • 自己处理方向变化
  • 我最好的建议是你应该控制自己。为此,你应该使用两件事:

  • 添加

    我尝试了@venky的答案,但我的布局受到干扰:(
    

    肖像画呢 此外,当方向改变时,按钮也不起作用:(

    
    
    是我的用于纵向和纵向的xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_lndscp"
    android:orientation="vertical" >
    
    <ImageView
        android:id="@+id/kalma1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="33dp"
        android:src="@drawable/kalma1" />
    
    
    <ImageView
        android:id="@+id/next1"
        android:layout_width="30dp"
        android:layout_height="20dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="3dp"
        android:layout_marginLeft="10dp"
        android:src="@drawable/forward" />
    
    
    
    <ImageView
        android:id="@+id/play1"
        android:layout_width="30dp"
        android:layout_height="20dp"
        android:layout_marginLeft="65dp"
        android:layout_marginTop="41dp"
        android:src="@drawable/play" />
    
    
    
    
    <ImageView
        android:id="@+id/pause1"
        android:layout_width="30dp"
        android:layout_height="20dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="41dp"
        android:src="@drawable/pause" />
    
    
    
    <ImageView
        android:id="@+id/home1"
        android:layout_width="30dp"
        android:layout_height="20dp"
        android:layout_alignBottom="@+id/play1"
        android:layout_alignRight="@+id/kalma1"
        android:src="@drawable/home" />
    
    </RelativeLayout>
    
    
    

    对于景观

    来说,它正在发挥作用,但干扰了布局:(是的,这是一个问题……正如我告诉过你的。你也尝试过所有其他答案吗?是的,我也尝试过其他答案。所有答案都是一样的:(@baig772那么为什么不为横向模式创建另一个XML,并将其保存在samei的layout land文件夹中?是否要阻止方向更改?请选中此项…使用oonRetainonConfiguration Instance()和GetLastNoConfiguration Instance()保存数据
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_prt"
    android:orientation="vertical" >
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:orientation="vertical" >
    
    </LinearLayout>
    
    
    
    
    
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="28dp"
        android:orientation="horizontal" >
    
        <ImageView
            android:id="@+id/pause1"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@drawable/pause" />
    
    
    
    
        <ImageView
            android:id="@+id/play1"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:src="@drawable/play" />
    
    
    
    
    
    
    
        <ImageView
            android:id="@+id/home1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="165dp"
            android:src="@drawable/home" />
    
    </LinearLayout>
    
    
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="315dp"
        android:orientation="vertical" >
    
    
        <ImageView
            android:id="@+id/kalma1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="40dp"
            android:layout_marginTop="20dp"
            android:src="@drawable/kalma1" />
    
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:orientation="horizontal" >
    
    
    
        <ImageView
            android:id="@+id/next1"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@drawable/forward" />
    
    </LinearLayout>
    
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_lndscp"
    android:orientation="vertical" >
    
    <ImageView
        android:id="@+id/kalma1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="33dp"
        android:src="@drawable/kalma1" />
    
    
    <ImageView
        android:id="@+id/next1"
        android:layout_width="30dp"
        android:layout_height="20dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="3dp"
        android:layout_marginLeft="10dp"
        android:src="@drawable/forward" />
    
    
    
    <ImageView
        android:id="@+id/play1"
        android:layout_width="30dp"
        android:layout_height="20dp"
        android:layout_marginLeft="65dp"
        android:layout_marginTop="41dp"
        android:src="@drawable/play" />
    
    
    
    
    <ImageView
        android:id="@+id/pause1"
        android:layout_width="30dp"
        android:layout_height="20dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="41dp"
        android:src="@drawable/pause" />
    
    
    
    <ImageView
        android:id="@+id/home1"
        android:layout_width="30dp"
        android:layout_height="20dp"
        android:layout_alignBottom="@+id/play1"
        android:layout_alignRight="@+id/kalma1"
        android:src="@drawable/home" />
    
    </RelativeLayout>