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

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

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

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

Android Studio

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

Q&A

解決済

1回答

1634閲覧

ImageButton の大きさを親 View にフィットさせたい

pectin

総合スコア95

Android

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

Android Studio

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

0グッド

0クリップ

投稿2018/07/31 02:58

ImageButton の大きさを親 View にフィットさせたい

DialogFragment で表示する View に ImageButton を平行に2つ並べています。
AndroidStudio 上では大きくなっているのですが、実機で表示すると大きくならない症状が発生しており、それを解決する方法を探しています。

ImageButton は、LinearLayout(Horizontal) 内に並べてあり、2つのボタンの layout_weight は 1 です。
画像は src に定義してあり、scaleType は fitCenter です。
background は #00000000(透明) です。

実機で表示すると、レイアウトとしては水平方向は均等割で表示しているのですが、ImageButton 自体のサイズが原寸のままで表示されているようです。

ImageButton の画像はアスペクト比を保ったまま大きくしたいです。

解決方法をご存知の方は教えていただけると助かります。

解決に必要な情報がございましたら、お申し付けください。

よろしくお願いします。

layout.xml

xml

1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:orientation="vertical"> 7 8 <FrameLayout 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content" 11 android:layout_gravity="center_horizontal"> 12 13 <LinearLayout 14 android:layout_width="match_parent" 15 android:layout_height="wrap_content" 16 android:layout_gravity="center" 17 android:layout_marginBottom="10dp" 18 android:layout_marginEnd="8dp" 19 android:layout_marginStart="8dp" 20 android:layout_marginTop="10dp" 21 android:background="@drawable/background_orange" 22 android:gravity="center_horizontal" 23 android:orientation="vertical"> 24 25 <ImageView 26 android:id="@+id/image_title" 27 android:layout_width="match_parent" 28 android:layout_height="wrap_content" 29 android:adjustViewBounds="true" 30 android:scaleType="fitCenter" 31 app:srcCompat="@mipmap/image_title" /> 32 33 <TextView 34 android:id="@+id/text_comment" 35 android:layout_width="match_parent" 36 android:layout_height="match_parent" 37 android:background="@null" 38 android:text="あああああいいいいいうううううえええええおおおおおあああああいいいいいうううううえええええおおおおおあああああいいいいいうううううえええええおおおおおあああああいいいいいうううううえええええおおおおおあああああいいいいいうううううえええええおおおおお" /> 39 40 <LinearLayout 41 android:layout_width="match_parent" 42 android:layout_height="match_parent" 43 android:orientation="horizontal"> 44 45 <ImageButton 46 android:id="@+id/button1" 47 android:layout_width="0dp" 48 android:layout_height="match_parent" 49 android:layout_weight="1" 50 android:adjustViewBounds="true" 51 android:background="#00000000" 52 android:scaleType="fitCenter" 53 android:src="@mipmap/button1" /> 54 55 <ImageButton 56 android:id="@+id/button2" 57 android:layout_width="0dp" 58 android:layout_height="match_parent" 59 android:layout_weight="1" 60 android:adjustViewBounds="true" 61 android:background="#00000000" 62 android:scaleType="fitCenter" 63 android:src="@mipmap/button2" /> 64 </LinearLayout> 65 66 </LinearLayout> 67 68 <ImageButton 69 android:id="@+id/dialog_close_button" 70 android:layout_width="30dp" 71 android:layout_height="30dp" 72 android:layout_gravity="top|end" 73 android:adjustViewBounds="true" 74 android:background="#00000000" 75 android:scaleType="fitCenter" 76 android:visibility="gone" 77 app:srcCompat="@mipmap/dialog_close_button" /> 78 79 </FrameLayout> 80 81</LinearLayout>

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

AndroidStudio3.1.2

説明画像

イメージ説明
イメージ説明

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

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

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

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

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

guest

回答1

0

ベストアンサー

LinearLayoutにweightSumの指定を入れることを忘れています。

xml

1 <LinearLayout 2 android:layout_width="match_parent" 3 android:layout_height="match_parent" 4 android:orientation="horizontal" 5 android:weightSum="2"> 6 7 <ImageButton 8 android:id="@+id/button1" 9 android:layout_width="0dp" 10 android:layout_height="match_parent" 11 android:layout_weight="1" 12 android:adjustViewBounds="true" 13 android:background="#00000000" 14 android:scaleType="fitCenter" 15 android:src="@mipmap/button1" /> 16 17 <ImageButton 18 android:id="@+id/button2" 19 android:layout_width="0dp" 20 android:layout_height="match_parent" 21 android:layout_weight="1" 22 android:adjustViewBounds="true" 23 android:background="#00000000" 24 android:scaleType="fitCenter" 25 android:src="@mipmap/button2" /> 26 </LinearLayout>

投稿2018/08/02 15:09

Shion_Ichikawa

総合スコア56

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

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

pectin

2018/08/06 05:58

ご連絡が遅くおなりましたが、ありがとうございました。 weightSum の場所をここではなく、もうひとつ上の階層(画像やテキストを表示しているレイアウト)に weightSum="3" として、画像・テキスト・ボタンの LinearLayout にそれぞれ layout_weight="1" をしてすることでボタンは大きく表示されるようになりました。 (その代わりテキスト部分の最下部が最後まで表示されない状態になってしまいましたが...)
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問