簡體   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