繁体   English   中英

横向和纵向定向模式问题

[英]landscape and portrait orientation mode issue

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

例:

现在正在播放2个音频。 但是,通过单击相同模式下的图像不会发生此问题。

更改模式时有没有办法停止上一个活动?

对于播放音频文件,只需使用Service不在Activity内播放,这样就可以停止服务,以便歌曲可以停止。 然后你应该专注于你将如何处理你的方向

  1. 重建活动
  2. 处理方向自行改变。

我最好的建议是你应该自己处理。为此,你应该使用两件事:


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

2.Call

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
  if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
          Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
   } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
     }
}

如果方向已更改,您应该根据需要处理服务。

AndroidManifest中添加此代码,其中包含您遇到问题的当前活动,但这会在您更改方向时停止更改app drawables,它将使用当前方向作为两种模式的静态,但仍尝试告诉我。

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

我试过@ venky的答案,但我的布局受到干扰:( 在此输入图像描述

在此输入图像描述

而对于肖像,当方向改变时,按钮也不起作用:(

<?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肖像和

<?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>

对于景观

暂无
暂无

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

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