2016-09-23 34 views
-1

起動ページにTextViewとImageViewを搭載した簡単なアンドロイドアプリを開発しています。携帯電話を横向きに回転させると、アプリがクラッシュします。アプリが殺されていないことがわかりますが、Androidスタジオでまだ実行中であることがわかります。続き は私のコードです:横向きに変更するとAndroidアプリがクラッシュする

Content_main.xml -landscapeモード

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.example.viral.myapplication2.MainActivity" 
    tools:showIn="@layout/activity_main"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" 
     android:id="@+id/textView2" /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/ganpati_bappa_moraya" 
     android:id="@+id/textView" 
     tools:context=".Blink" 
     android:textAlignment="center" 
     android:textSize="@dimen/abc_action_button_min_width_overflow_material" 
     android:layout_alignRight="@+id/imageView" 
     android:layout_alignEnd="@+id/imageView" 
     android:layout_alignLeft="@+id/imageView" 
     android:layout_alignStart="@+id/imageView" /> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/imageView" 
     android:layout_centerHorizontal="true" 
     android:src="@mipmap/god_pic" 
     android:layout_below="@+id/textView" /> 
</RelativeLayout> 

Content_main.xml - ノーマルモード用 - 肖像画

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.example.viral.myapplication2.MainActivity" 
    tools:showIn="@layout/activity_main"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" 
     android:id="@+id/textView2" /> 

    <TextView 
     android:layout_width="400dp" 
     android:layout_height="100dp" 
     android:text="Ganpati Bappa Moraya !!!" 
     android:id="@+id/textView" 
     android:layout_below="@+id/textView2" 
     android:layout_centerHorizontal="true" 
     tools:context=".Blink" 
     android:layout_marginTop="84dp" 
     android:textAlignment="center" 
     android:textSize="@dimen/abc_action_button_min_width_overflow_material" /> 

    <ImageView 
     android:layout_width="500dp" 
     android:layout_height="200dp" 
     android:id="@+id/imageView" 
     android:layout_below="@+id/textView" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="10dp" 
     android:src="@mipmap/god_pic" /> 
</RelativeLayout> 

Android_Manifest.xmlファイル

この

android:configChanges="keyboardHidden|orientation|screenSize". 

screenSize財産へ

+0

クラッシュのエラーを読んだり、あなたのアクティビティが何をしているかを調べたりしてください。 – JoxTraex

+1

logcatのエラー? –

+3

[オリエンテーションの変更クラッシュアプ​​リケーション]の重複の可能性があります(http://stackoverflow.com/questions/16806856/orientation-change-crash-application) – Soham

答えて

1

変更AndroidManifest.xmlファイルを再び呼び出しません画面の向きの変化や活動のライフサイクルについての世話をします。

+1

ありがとうございます。出来た。 – Vic

+0

私の喜び。:)もし私が助けてくれれば私の答えを受け入れる。 :) – LearnPainLess

関連する問題