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

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

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

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

Q&A

解決済

1回答

1696閲覧

LinearLayout での画像表示について

anz0527

総合スコア13

XML

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

0グッド

0クリップ

投稿2018/10/08 06:55

初心者のため、至らないところもあるかと思いますがお願いいたします。
現在、AndroiStudioでアプリを作成中です。
そこで、現在Layoutの、xmlファイルで画像のような表示になっています。
イメージ説明

そこでLAYOUTRIGHTボタンをImageViewにかえたいのですが、ボタン部分を置き換えると
画像が表示されません。
これはなぜでしょうか?また、表示させるにはどのようにすればよいのでしょうか?

お分かりの方、ぜひご教授いただけますようお願いいたします。

変更前:

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 android:paddingBottom="4dp" 7 android:paddingLeft="4dp" 8 android:paddingRight="4dp" 9 android:paddingTop="4dp"> 10 11 <RelativeLayout 12 android:layout_width="fill_parent" 13 android:layout_height="100dp" 14 android:weightSum="1"> 15 <LinearLayout 16 android:id="@+id/LayoutRight" 17 android:layout_width="wrap_content" 18 android:layout_height="100dp" 19 android:layout_alignParentLeft="true" 20 android:layout_above="@+id/LayoutDumy"> 21 <Button 22 android:layout_width="wrap_content" 23 android:layout_height="100dp" 24 android:text="LayoutRight"></Button> 25 </LinearLayout> 26 27 <LinearLayout 28 android:id="@+id/LayoutLeft" 29 android:layout_width="fill_parent" 30 android:layout_height="match_parent" 31 android:layout_toRightOf="@+id/LayoutRight" 32 android:orientation="vertical"> 33 <!-- 店名 --> 34 <TextView 35 android:id="@+id/text05ShopNm" 36 android:layout_width="wrap_content" 37 android:layout_height="wrap_content" 38 android:textColor="#000000" 39 android:textSize="20sp" /> 40 41 <LinearLayout 42 android:layout_width="match_parent" 43 android:layout_height="wrap_content" 44 android:orientation="horizontal" 45 android:weightSum="1"> 46 47 <!-- タイトル:コメント --> 48 <TextView 49 android:id="@+id/text05TitleComment" 50 android:layout_width="0dp" 51 android:layout_height="match_parent" 52 android:layout_weight="0.2" 53 android:text="@string/text05_title_Comment" 54 android:textSize="10sp" /> 55 56 <!-- データ表示用:コメント --> 57 <TextView 58 android:id="@+id/text05Comment" 59 android:layout_width="match_parent" 60 android:layout_height="65dp" 61 android:layout_weight="0.8" 62 android:textColor="#000000" 63 android:textSize="10sp" /> 64 </LinearLayout> 65 </LinearLayout> 66 67 <LinearLayout 68 android:id="@+id/LayoutDumy" 69 android:layout_width="0dp" 70 android:layout_height="wrap_content" 71 android:layout_below="@+id/LayoutLeft" 72 android:orientation="horizontal"> 73 </LinearLayout> 74 </RelativeLayout> 75</LinearLayout>

変更後:

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 android:paddingBottom="4dp" 7 android:paddingLeft="4dp" 8 android:paddingRight="4dp" 9 android:paddingTop="4dp"> 10 11 <RelativeLayout 12 android:layout_width="fill_parent" 13 android:layout_height="100dp" 14 android:weightSum="1"> 15 <LinearLayout 16 android:id="@+id/LayoutRight" 17 android:layout_width="wrap_content" 18 android:layout_height="100dp" 19 android:layout_alignParentLeft="true" 20 android:layout_above="@+id/LayoutDumy"> 21 22 <ImageView 23 android:id="@+id/image_view" 24 android:layout_width="wrap_content" 25 android:layout_height="100dp" 26 android:contentDescription="@string/description" 27 android:scaleType="fitCenter" /> 28 29 </LinearLayout> 30 31 <LinearLayout 32 android:id="@+id/LayoutLeft" 33 android:layout_width="fill_parent" 34 android:layout_height="match_parent" 35 android:layout_toRightOf="@+id/LayoutRight" 36 android:orientation="vertical"> 37 <!-- 店名 --> 38 <TextView 39 android:id="@+id/text05ShopNm" 40 android:layout_width="wrap_content" 41 android:layout_height="wrap_content" 42 android:textColor="#000000" 43 android:textSize="20sp" /> 44 45 <LinearLayout 46 android:layout_width="match_parent" 47 android:layout_height="wrap_content" 48 android:orientation="horizontal" 49 android:weightSum="1"> 50 51 <!-- タイトル:コメント --> 52 <TextView 53 android:id="@+id/text05TitleComment" 54 android:layout_width="0dp" 55 android:layout_height="match_parent" 56 android:layout_weight="0.2" 57 android:text="@string/text05_title_Comment" 58 android:textSize="10sp" /> 59 60 <!-- データ表示用:コメント --> 61 <TextView 62 android:id="@+id/text05Comment" 63 android:layout_width="match_parent" 64 android:layout_height="65dp" 65 android:layout_weight="0.8" 66 android:textColor="#000000" 67 android:textSize="10sp" /> 68 </LinearLayout> 69 </LinearLayout> 70 71 <LinearLayout 72 android:id="@+id/LayoutDumy" 73 android:layout_width="0dp" 74 android:layout_height="wrap_content" 75 android:layout_below="@+id/LayoutLeft" 76 android:orientation="horizontal"> 77 </LinearLayout> 78 </RelativeLayout> 79</LinearLayout>

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

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

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

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

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

guest

回答1

0

ベストアンサー

ボタンをImageViewにかえたい

何が目的なのかわかりませんが
単純にImageViewを設定して画像が表示されない
というのであれば、画像を指定していないだけです。

例えばimageという画像がdrawableにあるとすると
srcで設定します

<ImageView android:id="@+id/image_view" android:layout_width="wrap_content" android:layout_height="100dp" android:contentDescription="@string/description" android:scaleType="fitCenter" android:src="@drawable/image" />

もしも画像をタップしてボタンのようにしたいのであれば
ImageViewを置いただけではなにも起きません

やり方はいくつかありますが
例えばButtonのbackgroundに画像をしていするのも一つです

<Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/image" />

その他に、ImageButtonを使う方法もあります
ButtonとImageButtonは画像の指定により若干差があります。
リンク内容

また、ImageViewにonTouchを設定する方法もあるでしょう
リンク内容

投稿2018/10/08 09:15

aja

総合スコア3733

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

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

anz0527

2018/10/08 12:35

回答ありがとうございます! 枠だけつくってもデザインのところには反映されないのですね 一旦仮置きの画像を設定したら、表示されました。 本当にありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問