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

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

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

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

Android

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

Q&A

解決済

3回答

3782閲覧

wrap_contentが上手く動作しない

n_kazuki

総合スコア25

XML

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

Android

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

0グッド

0クリップ

投稿2016/03/15 13:15

現状のレイアウト(赤枠)と作成したいレイアウト(グレー)が下記のイメージです。
wrap_contentを使っていますが、赤枠のようにはみ出てしまう原因がわかりません。
背景は気にしないでください(適当なスクショを利用したため)
![イメージ説明

アドバイスをいただけると助かります。

xml

1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:orientation="vertical" 7 android:paddingBottom="10dp" 8 android:paddingRight="10dp" 9 android:paddingLeft="10dp"> 10 <LinearLayout 11 android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 android:orientation="vertical" 14 android:background="#FFFFFF" > 15 <LinearLayout 16 android:layout_width="wrap_content" 17 android:layout_height="wrap_content" 18 android:orientation="horizontal" 19 android:layout_marginTop="3dp" 20 android:layout_marginLeft="3dp" 21 android:layout_marginRight="3dp" > 22 <LinearLayout 23 android:layout_width="wrap_content" 24 android:layout_height="wrap_content" 25 android:orientation="vertical"> 26 <TextView 27 android:layout_width="wrap_content" 28 android:layout_height="wrap_content" 29 android:text="hogehoge" 30 android:textSize="20sp" 31 android:textColor="#FFA500" 32 android:textStyle="bold" 33 android:layout_margin="3dp" /> 34 <LinearLayout 35 android:layout_width="wrap_content" 36 android:layout_height="wrap_content" 37 android:orientation="horizontal" 38 android:layout_marginLeft="3dp" 39 android:layout_marginRight="3dp" > 40 <ImageView 41 android:layout_width="30dp" 42 android:layout_height="30dp" 43 android:src="@drawable/icon_hogehoge" 44 android:layout_margin="3dp" /> 45 <LinearLayout 46 android:layout_width="wrap_content" 47 android:layout_height="wrap_content" 48 android:orientation="vertical" 49 android:layout_margin="3dp" > 50 <LinearLayout 51 android:layout_width="wrap_content" 52 android:layout_height="wrap_content" 53 android:orientation="horizontal" > 54 <ImageView 55 android:layout_width="12dp" 56 android:layout_height="12dp" 57 android:src="@drawable/icon_hogehoge" /> 58 <TextView 59 android:layout_width="wrap_content" 60 android:layout_height="wrap_content" 61 android:text="hogehoge" 62 android:textSize="12sp" 63 android:textColor="#000000"/> 64 </LinearLayout> 65 <LinearLayout 66 android:layout_width="wrap_content" 67 android:layout_height="wrap_content" 68 android:orientation="horizontal" > 69 <ImageView 70 android:layout_width="12dp" 71 android:layout_height="12dp" 72 android:src="@drawable/icon_hogehoge" /> 73 <TextView 74 android:layout_width="wrap_content" 75 android:layout_height="wrap_content" 76 android:text="hogehoge" 77 android:textSize="12sp" 78 android:textColor="#000000" /> 79 </LinearLayout> 80 </LinearLayout> 81 </LinearLayout> 82 </LinearLayout> 83 <LinearLayout 84 android:layout_width="wrap_content" 85 android:layout_height="wrap_content" 86 android:orientation="vertical"> 87 <ImageView 88 android:layout_width="100dp" 89 android:layout_height="100dp" 90 android:src="@drawable/icon_hogehoge" 91 android:adjustViewBounds="true" /> 92 <LinearLayout 93 android:layout_width="wrap_content" 94 android:layout_height="wrap_content" 95 android:layout_gravity="center" 96 android:orientation="horizontal" 97 android:layout_marginTop="3dp"> 98 <ImageView 99 android:layout_width="15dp" 100 android:layout_height="15dp" 101 android:src="@drawable/icon_hogehoge" /> 102 <TextView 103 android:layout_width="wrap_content" 104 android:layout_height="wrap_content" 105 android:paddingLeft="3dp" 106 android:text="hogehoge" 107 android:textColor="#000000"/> 108 </LinearLayout> 109 </LinearLayout> 110 </LinearLayout> 111 </LinearLayout> 112</LinearLayout> 113

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

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

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

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

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

guest

回答3

0

どこのwrap_contentのことを言っているのか分からない上に、最終的にどのようなレイアウトにしたいのかも分かりません。
アドバイスはLinearLayoutに頼りすぎです、ViewGroupの入れ子は性能面や可読性が低下するのでRelaytiveLayoutなどの他のViewGroupを使用すべきだと思います。

投稿2016/03/15 13:37

yona

総合スコア18155

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

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

n_kazuki

2016/03/16 14:23

なるほど!LinearLayoutを最初に覚えたため、基本的にLinearLayoutで作成するパターンが多くなってしまっているので、RelativeLayoutを活用したレイアウト作りを心がけます。
guest

0

自己解決

<LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1">
</LinearLayout

でやりたいレイアウトできました。

投稿2016/03/17 12:23

n_kazuki

総合スコア25

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

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

guest

0

自分もそのレイアウトを試してみました。
イメージ説明
質問者さんの意図してるレイアウト通りかわかりませんが、xml通りに動いてます。

layout_weightを試しましたか?
もし試してなければお試しください。

リニアレイアウト (LinearLayout) の子の部品の配置 (重み付け)

投稿2016/03/15 13:49

shotakeu

総合スコア386

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

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

n_kazuki

2016/03/16 14:22

オレンジ色のhogehogeを長い文字列にしてみてください。 そうすると現象にはまるはずです。 お時間ありましたら確認お願いします。。。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問