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

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

新規登録して質問してみよう
ただいま回答率
85.49%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Q&A

解決済

1回答

686閲覧

Androidアプリ内で画像が表示されない

BIWD

総合スコア10

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

0グッド

1クリップ

投稿2023/06/09 03:41

実現したいこと

・<ImageView>内の@drawable/peopleが表示されるようにする

前提

AndroidStudioでSNSのマイページ画面のようなものを作っています。
が、アイコンである画像の@drawable/peopleが表示されません。

発生している問題・エラーメッセージ

11586-11636/com.example.mypage E/ion: ioctl c0044901 failed with code -1: Invalid argument 11586-11586/com.example.mypage E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"

該当のソースコード

activity_main.xml

1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:orientation="vertical" 7 tools:context=".MainActivity"> 8 9 <LinearLayout 10 android:layout_width="match_parent" 11 android:layout_height="wrap_content"/> 12 13 <LinearLayout 14 android:layout_width="match_parent" 15 android:layout_height="230dp" 16 android:orientation="vertical" 17 android:background="@drawable/mycolor"> 18 19 <Space android:layout_width="match_parent" 20 android:layout_height="10dip"/> 21 22 <LinearLayout 23 android:layout_width="200dp" 24 android:layout_height="wrap_content" 25 android:orientation="vertical" 26 android:background="@color/white" 27 android:layout_gravity="center"> 28 29 30 <ImageView 31 android:id="@+id/imageprf" 32 android:layout_width="50dp" 33 android:layout_height="50dp" 34 android:layout_gravity="center" 35 tools:src="@drawable/people" /> 36 37 <TextView 38 android:id="@+id/nameprf" 39 android:layout_width="wrap_content" 40 android:layout_height="wrap_content" 41 android:text="なまえ" 42 android:textSize="15dp" 43 android:layout_gravity="center"/> 44 45 <TextView 46 android:layout_width="wrap_content" 47 android:layout_height="wrap_content" 48 android:text="スコア" 49 android:textSize="10dp" 50 android:layout_gravity="center"/> 51 52 <TextView 53 android:layout_width="wrap_content" 54 android:layout_height="wrap_content" 55 android:text="00.0" 56 android:textSize="40dp" 57 android:layout_gravity="center" /> 58 59 </LinearLayout> 60 61 <TextView 62 android:layout_width="match_parent" 63 android:layout_height="wrap_content" 64 android:text="プロフィール" 65 android:textColor="@color/textcolor_normal"/> 66 67 <TextView 68 android:id="@+id/textprf" 69 android:layout_width="wrap_content" 70 android:layout_height="wrap_content" 71 android:textSize="15dp" 72 android:text="" 73 android:textColor="@color/textcolor_light"/> 74 75 <Button 76 android:id="@+id/editprf" 77 android:layout_width="wrap_content" 78 android:layout_height="wrap_content" 79 android:backgroundTint="@color/maincolor_blue" 80 android:layout_gravity="right" 81 android:textSize="10dp" 82 android:minHeight="0dp" 83 android:minWidth="0dp" 84 android:text="へんしゅう" /> 85 86 </LinearLayout> 87 88 89 <LinearLayout 90 android:layout_width="match_parent" 91 android:layout_height="wrap_content" 92 android:orientation="vertical" 93 android:background="@color/background_gray"> 94 95 </LinearLayout> 96 97 <LinearLayout 98 android:layout_width="match_parent" 99 android:layout_height="0dp" 100 android:layout_weight="1" /> 101 102</LinearLayout>

dialog_edit.xml

1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 android:orientation="vertical"> 6 7 <EditText 8 android:id="@+id/nameEditText" 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content" 11 android:hint="✏なまえをいれてね" /> 12 13 <EditText 14 android:id="@+id/textEditText" 15 android:layout_width="match_parent" 16 android:layout_height="wrap_content" 17 android:hint="✏あなたのことをおしえて" /> 18 19 <Button 20 android:id="@+id/saveButton" 21 android:layout_width="wrap_content" 22 android:layout_height="wrap_content" 23 android:backgroundTint="@color/maincolor_blue" 24 android:text="ほぞん" /> 25 26</LinearLayout>

circle.xml

1<shape xmlns:android="http://schemas.android.com/apk/res/android"> 2 <solid android:color="@color/white" /> 3 <corners android:radius="1000dp" /> <!-- 十分に大きな値を指定します --> 4</shape> 5

colors.xml

1<?xml version="1.0" encoding="utf-8"?> 2<resources> 3 <color name="purple_200">#FFBB86FC</color> 4 <color name="purple_500">#FF6200EE</color> 5 <color name="purple_700">#FF3700B3</color> 6 <color name="teal_200">#FF03DAC5</color> 7 <color name="teal_700">#FF018786</color> 8 <color name="black">#FF000000</color> 9 <color name="white">#FFFFFFFF</color> 10 <color name="maincolor_green">#6BCB77</color> 11 <color name="maincolor_red">#FF6B6B</color> 12 <color name="maincolor_blue">#4D96FF</color> 13 <color name="maincolor_yellow">#FFD93D</color> 14 <color name="background_gray">#EFEDED</color> 15 <color name="textcolor_light">#C4C2C2</color> 16 <color name="textcolor_normal">#6B6A6A</color> 17</resources>

MainActivity.java

1package com.example.mypage; 2 3 4import android.content.SharedPreferences; 5import android.os.Bundle; 6import android.preference.PreferenceManager; 7import android.view.View; 8import android.widget.Button; 9import android.widget.EditText; 10import android.widget.TextView; 11 12import androidx.appcompat.app.AlertDialog; 13import androidx.appcompat.app.AppCompatActivity; 14 15public class MainActivity extends AppCompatActivity { 16 17 private TextView nameTextView; 18 private TextView textTextView; 19 private Button editButton; 20 21 private SharedPreferences sharedPreferences; 22 23 @Override 24 protected void onCreate(Bundle savedInstanceState) { 25 super.onCreate(savedInstanceState); 26 setContentView(R.layout.activity_main); 27 28 nameTextView = findViewById(R.id.nameprf); 29 textTextView = findViewById(R.id.textprf); 30 editButton = findViewById(R.id.editprf); 31 32 sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); 33 34 // 保存された情報を取得して表示 35 String savedName = sharedPreferences.getString("name", ""); 36 String savedText = sharedPreferences.getString("text", ""); 37 nameTextView.setText(savedName); 38 textTextView.setText(savedText); 39 40 editButton.setOnClickListener(new View.OnClickListener() { 41 @Override 42 public void onClick(View v) { 43 showEditDialog(); 44 } 45 }); 46 } 47 48 private void showEditDialog() { 49 AlertDialog.Builder builder = new AlertDialog.Builder(this); 50 View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit, null); 51 builder.setView(dialogView); 52 53 final EditText nameEditText = dialogView.findViewById(R.id.nameEditText); 54 final EditText textEditText = dialogView.findViewById(R.id.textEditText); 55 Button saveButton = dialogView.findViewById(R.id.saveButton); 56 57 AlertDialog alertDialog = builder.create(); 58 59 // 保存ボタンが押されたときの処理 60 saveButton.setOnClickListener(new View.OnClickListener() { 61 @Override 62 public void onClick(View v) { 63 String newName = nameEditText.getText().toString(); 64 String newText = textEditText.getText().toString(); 65 66 // 入力された値を表示 67 nameTextView.setText(newName); 68 textTextView.setText(newText); 69 70 // 共有プリファレンスに値を保存 71 SharedPreferences.Editor editor = sharedPreferences.edit(); 72 editor.putString("name", newName); 73 editor.putString("text", newText); 74 editor.apply(); 75 76 // ダイアログを閉じる 77 alertDialog.dismiss(); 78 } 79 }); 80 81 alertDialog.show(); 82 } 83} 84

試したこと

LinearLayoutのheightの値を大きくしたり小さくしたり

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

・プログラミング言語はjavaです。
・Nexus6 API28、Nexus6P API28 や android実機を利用してテストしています。
・people.pngは適当なフリー素材です↓↓
イメージ説明

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

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

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

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

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

jimbe

2023/06/09 08:25

>tools:src="@drawable/people" もしやこのことでしょうか。 だとしたら、 tools はツール向けの定義で、実際の動作時には無視されると思います。
jimbe

2023/06/09 11:17

ついでに、 LinerLayout で隙間を作ったりするのは悪い方法です。 マージンやパティング等を適切に使ったほうが良いと思います。
BIWD

2023/06/10 15:41

丁寧な回答ありがとうございます。 勉強不足で稚拙な質問をしてしまいお恥ずかしい限りです。 アドバイスとてもありがたいです。改善させていただきます。
guest

回答1

0

自己解決

activity_main.xmlの
tools:src="@drawable/people" という行を
android:src="@drawable/people" に変更したら成功しました。
大変初歩的な質問で恥ずかしいのですが、誰かの為になるかと思い残しておきます。
親切に回答をくださった方、ありがとうございました。

投稿2023/06/10 15:50

BIWD

総合スコア10

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.49%

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

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

質問する

関連した質問