質問編集履歴
1
1、質問、回答、再質問、回答、再質問等を列挙。2、画像を添付。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
アンドロイドスタジオ ConstraintLayoutで背景画像を表示
|
1
|
+
アンドロイドスタジオ ConstraintLayoutで背景画像を表示(再投稿)
|
body
CHANGED
@@ -1,29 +1,42 @@
|
|
1
|
+
△編集しての投稿
|
2
|
+
|
3
|
+
~ teratailよりメールを頂き、再投稿させて頂きます。
|
4
|
+
~ 再編集と言っても、質問⇒回答⇒再質問⇒回答を待つを列挙したに過ぎません。
|
5
|
+
~ 画像を添付します。(初めの質問で添付するつもりが忘れました)
|
6
|
+
~ 以下、見てお分かりのように超初心者なので、勝手ながらご助言は、手順を追ってして頂けると、目下の幸いです。
|
7
|
+
~ よろしくお願いいたします。
|
8
|
+
|
9
|
+
|
10
|
+
アンドロイドスタジオ ConstraintLayoutで背景画像を表示
|
11
|
+
|
12
|
+
投稿 2019/11/22 18:28
|
13
|
+
|
1
14
|
私は、あるテキストを見ながらConstraintLayoutで背景画像を表示してみよう思いました。(超初心者)
|
2
15
|
Android Studioのプレビュー画面では、画像は正しく表示されていますが、エミュレータ起動すると、画像が表示されません。
|
16
|
+
|
3
|
-
|
17
|
+
以下は私が使っているコードです。
|
4
|
-
|
5
|
-
<?xml version="1.0" encoding="utf-8"?>
|
18
|
+
<?xml version="1.0" encoding="utf-8"?>
|
6
|
-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
19
|
+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
7
|
-
|
20
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
8
|
-
|
21
|
+
xmlns:tools="http://schemas.android.com/tools"
|
9
|
-
|
22
|
+
android:layout_width="match_parent"
|
10
|
-
|
23
|
+
android:layout_height="match_parent"
|
11
|
-
|
24
|
+
tools:context=".MainActivity">
|
12
|
-
|
25
|
+
|
13
|
-
|
26
|
+
<ImageView
|
14
|
-
|
27
|
+
android:layout_width="wrap_content"
|
15
|
-
|
28
|
+
android:layout_height="wrap_content"
|
16
|
-
|
29
|
+
android:text="Hello World!"
|
17
|
-
|
30
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
18
|
-
|
31
|
+
app:layout_constraintLeft_toLeftOf="parent"
|
19
|
-
|
32
|
+
app:layout_constraintRight_toRightOf="parent"
|
20
|
-
|
33
|
+
app:layout_constraintTop_toTopOf="parent" />
|
21
|
-
|
34
|
+
|
22
|
-
</androidx.constraintlayout.widget.ConstraintLayout>
|
35
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
23
|
-
|
36
|
+
|
24
|
-
|
37
|
+
Android StudioのUIプレビューを添付します
|
25
38
|
画像①
|
26
|
-
|
39
|
+
で、エミュレータを起動しても表示されません。以下は起動したエミュレータのスクリーンショットです。
|
27
40
|
画像②
|
28
41
|
|
29
42
|
実現したいことは、起動したエミュレータに背景画像を表示する手順をおしえてください。
|
@@ -31,29 +44,162 @@
|
|
31
44
|
尚、テキスト作成者とは、連絡が取れません。(正確には、連絡先は分かりません。)
|
32
45
|
で、私の環境は、Windows10、アンドロイドスタジオは最新です。
|
33
46
|
宜しくお願いします。
|
34
|
-
|
35
|
-
## 前提・実現したいこと
|
36
47
|
|
37
|
-
|
48
|
+
△で、以下に回答を頂きました。
|
38
|
-
(例)PHP(CakePHP)で●●なシステムを作っています。
|
39
|
-
■■な機能を実装中に以下のエラーメッセージが発生しました。
|
40
49
|
|
41
|
-
|
50
|
+
回答 1 件
|
42
51
|
|
52
|
+
res_drawableに保存した画像「画像名.jpg」(仮にjpg)を表示するには
|
43
|
-
|
53
|
+
MainActivityでイメージビューにセットする必要があります
|
44
|
-
|
54
|
+
kotlinですいません
|
45
|
-
```
|
46
55
|
|
47
|
-
### 該当のソースコード
|
48
56
|
|
49
|
-
|
57
|
+
class MainActivity : AppCompatActivity() {
|
50
|
-
ソースコード
|
51
|
-
```
|
52
58
|
|
59
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
53
|
-
|
60
|
+
super.onCreate(savedInstanceState)
|
61
|
+
setContentView(R.layout.activity_main)
|
54
62
|
|
63
|
+
imageView1.setImageResource(R.drawable.画像名)
|
64
|
+
}
|
65
|
+
}
|
55
|
-
|
66
|
+
XMLではその画面でどんな感じで見えるか試すために画像選択をしてるだけです
|
56
67
|
|
57
|
-
|
68
|
+
投稿 2019/11/22 20:32
|
58
69
|
|
70
|
+
Hiroshi_Kito
|
71
|
+
Hiroshi_Kito
|
72
|
+
score 24
|
73
|
+
|
74
|
+
△再質問。(以下)
|
75
|
+
|
76
|
+
2019/11/22 22:11
|
77
|
+
|
78
|
+
早々の解答有り難うございます。
|
79
|
+
ご助言、頂きましたが私が超初心者なので申し訳ないです。
|
80
|
+
一応、下記のように書きました。
|
81
|
+
▲立ち上げ時のコード
|
82
|
+
|
83
|
+
package com.example.myapplication005;
|
84
|
+
|
85
|
+
import androidx.appcompat.app.AppCompatActivity;
|
86
|
+
|
87
|
+
import android.os.Bundle;
|
88
|
+
|
89
|
+
public class MainActivity extends AppCompatActivity {
|
90
|
+
|
91
|
+
@Override
|
92
|
+
protected void onCreate(Bundle savedInstanceState) {
|
93
|
+
super.onCreate(savedInstanceState);
|
94
|
+
setContentView(R.layout.activity_main);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
▲記述したコード
|
98
|
+
|
99
|
+
package com.example.myapplication005;
|
100
|
+
|
101
|
+
import androidx.appcompat.app.AppCompatActivity;
|
102
|
+
|
103
|
+
import android.os.Bundle;
|
104
|
+
|
105
|
+
public class MainActivity extends AppCompatActivity {
|
106
|
+
|
107
|
+
@Override
|
108
|
+
protected void onCreate(Bundle savedInstanceState) {
|
109
|
+
super.onCreate(savedInstanceState);
|
110
|
+
setContentView(R.layout.activity_main);
|
111
|
+
|
112
|
+
imageView1.setImageResource(R.drawable.back);
|
113
|
+
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
・・・で、画像名は「 back 」です。
|
118
|
+
・・・エラーが、「シンボル'imageView1'を解決できません」
|
119
|
+
・・・エミュレータを一応、起動しましたがだめです。
|
120
|
+
宜しくお願いします。
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
△回答
|
125
|
+
Hiroshi_Kito
|
126
|
+
Hiroshi_Kito
|
127
|
+
2019/11/22 22:35
|
128
|
+
|
129
|
+
imageView1 はレイアウトxml画面で設定した ID の名前です
|
130
|
+
xmlの画面で設定してください
|
131
|
+
|
132
|
+
質問内容を見てみると
|
133
|
+
TextViewをImageViewと文字だけ変えてるのかな?
|
134
|
+
Text→Design画面にしてImageViewを置いてからid設定してください
|
135
|
+
|
136
|
+
画像は[res]-[drawable]に入ってますよね?
|
137
|
+
|
59
|
-
こ
|
138
|
+
この3つを確認してください
|
139
|
+
NayamiMondai
|
140
|
+
NayamiMondai
|
141
|
+
|
142
|
+
△再質問
|
143
|
+
2019/11/23 16:07
|
144
|
+
|
145
|
+
お手数をおかけします。
|
146
|
+
二回目のご助言に基づいて行いましたが、駄目でした。
|
147
|
+
私のご助言の読解に問題がると思い、下記に記しました。
|
148
|
+
査収の程、お願い申し上げます。
|
149
|
+
|
150
|
+
1、以下の手順で、xmlの画面を表示しましたが…間違いありませんか?
|
151
|
+
app → src → main → res → layout → activity → activity_main.xml
|
152
|
+
|
153
|
+
2、id設定の画面です。(全く自信ありません)
|
154
|
+
|
155
|
+
*立ち上げ画面
|
156
|
+
↓
|
157
|
+
<?xml version="1.0" encoding="utf-8"?>
|
158
|
+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
159
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
160
|
+
xmlns:tools="http://schemas.android.com/tools"
|
161
|
+
android:layout_width="match_parent"
|
162
|
+
android:layout_height="match_parent"
|
163
|
+
tools:context=".MainActivity">
|
164
|
+
|
165
|
+
<ImageView
|
166
|
+
app:layout_constraintLeft_toLeftOf="parent"
|
167
|
+
app:layout_constraintRight_toRightOf="parent"
|
168
|
+
app:layout_constraintTop_toTopOf="parent"
|
169
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
170
|
+
android:src="@drawable/back"
|
171
|
+
android:scaleType="centerCrop"
|
172
|
+
android:layout_width="0dp"
|
173
|
+
android:layout_height="0dp"/>
|
174
|
+
|
175
|
+
</androidx.constraintlayout.widg
|
176
|
+
|
177
|
+
* id設定画面
|
178
|
+
↓
|
179
|
+
<?xml version="1.0" encoding="utf-8"?>
|
180
|
+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
181
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
182
|
+
xmlns:tools="http://schemas.android.com/tools"
|
183
|
+
android:layout_width="match_parent"
|
184
|
+
android:layout_height="match_parent"
|
185
|
+
tools:context=".MainActivity">
|
186
|
+
|
187
|
+
<ImageView
|
188
|
+
android:id="@+id/image" → id設定コード
|
189
|
+
app:layout_constraintLeft_toLeftOf="parent"
|
190
|
+
app:layout_constraintRight_toRightOf="parent"
|
191
|
+
app:layout_constraintTop_toTopOf="parent"
|
192
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
193
|
+
android:src="@drawable/back"
|
194
|
+
android:scaleType="centerCrop"
|
195
|
+
android:layout_width="0dp"
|
196
|
+
android:layout_height="0dp"/>
|
197
|
+
|
198
|
+
</androidx.constraintlayout.widget.Constraint
|
199
|
+
|
200
|
+
3、画像は、間違いなく入っております。
|
201
|
+
|
202
|
+
以上、よろしくお願いいたします。
|
203
|
+
|
204
|
+
以下に、画像を添付します
|
205
|
+

|