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

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

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

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

解決済

1回答

657閲覧

AndroidでTextViewとImageViewを並べると画像が表示されない

yrema

総合スコア286

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

0クリップ

投稿2018/02/14 08:47

タイトルの通りですが、
やりたいことは左にテキスト、右に画像(150dp固定)を表示したいです。
ところが、以下の画像のようにテキストが画像を押し出してしまっているようです。
何が間違っているのでしょうか。
イメージ説明

レイアウトは以下の通りです。

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 <LinearLayout 8 android:layout_width="match_parent" 9 android:layout_height="wrap_content" 10 android:orientation="horizontal"> 11 12 <TextView 13 android:id="@+id/explanation_text" 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:textColor="@android:color/black" 17 android:text="ああああああああああああああああああああああああああああああああああああああああああああ"/> 18 19 <LinearLayout 20 android:layout_width="150dp" 21 android:layout_height="wrap_content" 22 android:padding="1dp" 23 android:background="@color/line_gray" 24 android:orientation="vertical"> 25 <ImageView 26 android:id="@+id/image" 27 android:layout_width="match_parent" 28 android:layout_height="wrap_content" 29 android:adjustViewBounds="true" 30 android:scaleType="fitCenter" 31 android:src="@drawable/googlelogo"/> 32 </LinearLayout> 33 </LinearLayout> 34</LinearLayout> 35

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

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

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

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

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

guest

回答1

0

ベストアンサー

これでできませんか?TextViewにandroid:layout_weight="1"を、ImageViewを囲っているLinearLayoutにandroid:layout_gravity="end"を追加しています。

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 <LinearLayout 8 android:layout_width="match_parent" 9 android:layout_height="wrap_content" 10 android:orientation="horizontal"> 11 12 <TextView 13 android:id="@+id/explanation_text" 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:layout_weight="1" 17 android:text="ああああああああああああああああああああああああああああああああああああああああああああ" 18 android:textColor="@android:color/black" /> 19 20 <LinearLayout 21 android:layout_width="150dp" 22 android:layout_height="wrap_content" 23 android:layout_gravity="end" 24 android:background="@color/line_gray" 25 android:orientation="vertical" 26 android:padding="1dp"> 27 28 <ImageView 29 android:id="@+id/image" 30 android:layout_width="match_parent" 31 android:layout_height="wrap_content" 32 android:adjustViewBounds="true" 33 android:scaleType="fitCenter" 34 android:src="@drawable/googlelogo" /> 35 </LinearLayout> 36 </LinearLayout> 37</LinearLayout>

投稿2018/02/14 16:11

編集2018/02/14 16:14
keicha_hrs

総合スコア6766

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

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

yrema

2018/02/15 01:42

android:layout_gravity="end" は思いつきませんでした。ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問