質問編集履歴
2
質問内容を完結にした
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
タテ画面
|
1
|
+
タテ画面、ヨコ画面でフラグメントを使い分けるとエミュレータでエラー(クラッシュ)が起きてしまいます。
|
test
CHANGED
File without changes
|
1
質問内容を変更した
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
タテ画面でフラグメントA、ヨコ画面でフラグメントB、と使い分けるとエミュレータでエラー(クラッシュ)が起きてしまいます。
|
test
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
### 前提
|
2
2
|
|
3
|
-
kotlinで
|
3
|
+
kotlinでlandscapeの勉強をしている。
|
4
4
|
|
5
5
|
### 実現したいこと
|
6
6
|
|
7
|
-
今やったのは下記。
|
8
|
-
1)タテ画面⇒FragmentA、1つを表示
|
9
|
-
2)ヨコ画面⇒FragmentAとFragmentB、2つを表示
|
10
|
-
というように表示するようにアクティビティに設定しています。
|
11
|
-
|
12
|
-
|
7
|
+
タテ画面でフラグメントA、ヨコ画面でフラグメントB、と使い分けるとエミュレータでエラー(クラッシュ)が起きてしまいます。
|
13
|
-
「2」が読み込みされず、どういう記述が必要なのか教えて欲しい。
|
14
8
|
|
15
9
|
|
16
10
|
|
@@ -27,7 +21,6 @@
|
|
27
21
|
tools:context=".MainActivity">
|
28
22
|
|
29
23
|
<androidx.fragment.app.FragmentContainerView
|
30
|
-
android:id="@+id/FragmentContainerView"
|
31
24
|
android:name="com.example.sampletera.FragmentA"
|
32
25
|
android:layout_width="match_parent"
|
33
26
|
android:layout_height="match_parent" />
|
@@ -45,70 +38,18 @@
|
|
45
38
|
tools:context=".MainActivity">
|
46
39
|
|
47
40
|
<androidx.fragment.app.FragmentContainerView
|
48
|
-
android:name="com.example.sampletera.FragmentA"
|
49
|
-
android:layout_width="0dp"
|
50
|
-
android:layout_height="match_parent"
|
51
|
-
android:layout_weight="1" />
|
52
|
-
|
53
|
-
<androidx.fragment.app.FragmentContainerView
|
54
41
|
android:name="com.example.sampletera.FragmentB"
|
55
42
|
android:layout_width="0dp"
|
56
43
|
android:layout_height="match_parent"
|
57
44
|
android:layout_weight="1" />
|
58
|
-
|
45
|
+
|
59
46
|
</LinearLayout>
|
60
47
|
```
|
61
|
-
```MainActivity.kt
|
62
|
-
package com.example.sampletera
|
63
48
|
|
64
|
-
import androidx.appcompat.app.AppCompatActivity
|
65
|
-
import android.os.Bundle
|
66
|
-
|
67
|
-
class MainActivity : AppCompatActivity() {
|
68
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
69
|
-
super.onCreate(savedInstanceState)
|
70
|
-
setContentView(R.layout.activity_main)
|
71
|
-
}
|
72
|
-
}
|
73
|
-
```
|
74
|
-
```AndroidManifest.xml
|
75
|
-
<?xml version="1.0" encoding="utf-8"?>
|
76
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
77
|
-
package="com.example.sampletera">
|
78
|
-
|
79
|
-
<application
|
80
|
-
android:allowBackup="true"
|
81
|
-
android:icon="@mipmap/ic_launcher"
|
82
|
-
android:label="@string/app_name"
|
83
|
-
android:roundIcon="@mipmap/ic_launcher_round"
|
84
|
-
android:supportsRtl="true"
|
85
|
-
android:theme="@style/Theme.SampleTera">
|
86
|
-
<activity
|
87
|
-
android:name=".MainActivity"
|
88
|
-
android:configChanges="orientation|screenSize"
|
89
|
-
android:exported="true">
|
90
|
-
<intent-filter>
|
91
|
-
<action android:name="android.intent.action.MAIN" />
|
92
|
-
|
93
|
-
<category android:name="android.intent.category.LAUNCHER" />
|
94
|
-
</intent-filter>
|
95
|
-
</activity>
|
96
|
-
</application>
|
97
|
-
|
98
|
-
</manifest>
|
99
|
-
```
|
100
49
|
|
101
50
|
### 試したこと
|
102
51
|
|
103
|
-
最初、Fragmentとxmlを作っただけの状態だと、
|
104
|
-
エミュレータを起動すると、クラッシュしてしまいました。
|
105
|
-
原因を調べてみるとAndroidManifest.xmlに
|
106
|
-
android:configChanges="orientation|screenSize"
|
107
|
-
を記述するような記事を見つけたので、それを追記。
|
108
|
-
|
109
|
-
|
52
|
+
フラグメントではなく、普通にviewを表示した場合はタテ画面と横画面で使い分けができている。
|
110
|
-
が、タテもヨコも「同じアクティビティ」が読み込まれているようで
|
111
|
-
landの方が読み込みされていないようで困っています。
|
112
53
|
|
113
54
|
### 補足情報(FW/ツールのバージョンなど)
|
114
55
|
|