質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.51%
Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

2004閲覧

activity_main.xmlとエミュレータの画面が一致しない

KouAsano

総合スコア9

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2017/07/01 13:00

###前提・実現したいこと
本日androidアプリ開発を始めた初心者です。
とりあえず画像を表示させようとしています。

###発生している問題・エラーメッセージ
activity_main.xmlで表示されている画像がエミュレータを起動すると表示することができないです
イメージ説明
イメージ説明

エラーメッセージ

###該当のソースコード

xml

1<?xml version="1.0" encoding="utf-8"?> 2<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context="com.example.asanokou.myapplication.MainActivity"> 8 9 <TextView 10 android:layout_width="wrap_content" 11 android:layout_height="wrap_content" 12 android:text="@string/hello" 13 app:layout_constraintBottom_toBottomOf="parent" 14 app:layout_constraintLeft_toLeftOf="parent" 15 app:layout_constraintRight_toRightOf="parent" 16 app:layout_constraintTop_toTopOf="parent" 17 app:layout_constraintHorizontal_bias="0.326" 18 app:layout_constraintVertical_bias="0.174" /> 19 20 <Button 21 android:id="@+id/button" 22 android:layout_width="wrap_content" 23 android:layout_height="wrap_content" 24 25 android:text="Button" 26 tools:layout_constraintTop_creator="1" 27 tools:layout_constraintLeft_creator="1" 28 app:layout_constraintLeft_toLeftOf="parent" 29 app:layout_constraintTop_toTopOf="parent" /> 30 31 <ImageView 32 android:id="@+id/imageView" 33 android:layout_width="86dp" 34 android:layout_height="66dp" 35 app:srcCompat="@mipmap/ic_launcher" 36 tools:layout_constraintTop_creator="1" 37 android:layout_marginStart="29dp" 38 android:layout_marginTop="68dp" 39 app:layout_constraintTop_toBottomOf="@+id/button" 40 tools:layout_constraintLeft_creator="1" 41 app:layout_constraintLeft_toLeftOf="parent" 42 android:layout_marginLeft="29dp" 43 android:contentDescription="test"/> 44 45</android.support.constraint.ConstraintLayout> 46

###試したこと
ネットで検索して調べて試してみたのですが解決することができませんでした

###補足情報(言語/FW/ツール等のバージョンなど)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

ConstraintLayoutは初心者には難しいので、RelativeLayoutを使うことをオススメします。

投稿2017/07/01 13:06

yona

総合スコア18155

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

KouAsano

2017/07/02 07:26 編集

ConstraintLayoutからRelativeLayoutに変更しましたが、画像だけがエミュレータに表示されないです。なぜなのでしょうか... <?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" tools:context="com.example.asanokou.myapplication.MainActivity"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="89dp" android:text="@string/hello" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_centerVertical="true" android:layout_marginLeft="31dp" android:layout_marginStart="31dp" android:text="Button" /> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@mipmap/ic_launcher" android:layout_below="@+id/textView" android:layout_centerHorizontal="true" android:layout_marginTop="35dp" android:contentDescription="test"/> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView" android:layout_alignStart="@+id/textView" android:layout_alignTop="@+id/button" android:layout_marginLeft="7dp" android:layout_marginStart="7dp" android:text="Button" /> </RelativeLayout>
yona

2017/07/02 10:43

srcCompat属性ではなく、src属性で画像を指定してください。
KouAsano

2017/07/04 01:10

表示することができました!ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.51%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問