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

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

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

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

Java

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

Android Studio

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

Q&A

解決済

1回答

1433閲覧

Viewを均等に配置する

sena14

総合スコア109

XML

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

Java

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

Android Studio

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

0グッド

0クリップ

投稿2018/06/07 18:53

大きさの決まったView(縦横50dp)のものを決まった個数だけ(15個)を最初と最後が親Viewの一番上と一番下になるように縦一列に配置したいです。納まりきらない場合は重ねて、逆に足りない場合は一番上と一番下を合わせて均等に余白を付けたいです。
親Viewの高さはlayout_weghtで大きさを決定してるため変動します。
このような条件の場合xml内の記述だけで実装できますでしょうか?

よろしくお願いします。

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

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

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

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

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

guest

回答1

0

ベストアンサー

xml内の記述だけで実装できると思います。
赤の四角は(縦横50dp)でサイズを固定しています。余白を緑の四角で埋めている状態です。

3個の場合
イメージ説明

14個の場合
イメージ説明

15個の場合:余白(緑の部分)が無いように見えますが、設定しています。
イメージ説明

以下のコードは15個を縦一列に配置したときのものになります。

xml

1<?xml version="1.0" encoding="utf-8"?> 2<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity" 8 > 9 10 <!-- 親View --> 11 <LinearLayout 12 android:layout_width="match_parent" 13 android:layout_height="match_parent" 14 android:background="#cccccc" 15 android:gravity="center" 16 android:orientation="vertical" 17 tools:layout_editor_absoluteY="0dp" 18 tools:ignore="MissingConstraints"> 19 20 <TextView 21 android:layout_width="50dp" 22 android:layout_height="50dp" 23 android:background="#ff6969" /> 24 25 <TextView 26 android:layout_width="50dp" 27 android:layout_height="0dp" 28 android:layout_weight="1" 29 android:background="#57d978" /> 30 31 <TextView 32 android:layout_width="50dp" 33 android:layout_height="50dp" 34 android:background="#ff6969" /> 35 36 <TextView 37 android:layout_width="50dp" 38 android:layout_height="0dp" 39 android:layout_weight="1" 40 android:background="#57d978" /> 41 42 <TextView 43 android:layout_width="50dp" 44 android:layout_height="50dp" 45 android:background="#ff6969" /> 46 47 <TextView 48 android:layout_width="50dp" 49 android:layout_height="0dp" 50 android:layout_weight="1" 51 android:background="#57d978" /> 52 53 <TextView 54 android:layout_width="50dp" 55 android:layout_height="50dp" 56 android:background="#ff6969" /> 57 58 <TextView 59 android:layout_width="50dp" 60 android:layout_height="0dp" 61 android:layout_weight="1" 62 android:background="#57d978" /> 63 64 <TextView 65 android:layout_width="50dp" 66 android:layout_height="50dp" 67 android:background="#ff6969" /> 68 69 <TextView 70 android:layout_width="50dp" 71 android:layout_height="0dp" 72 android:layout_weight="1" 73 android:background="#57d978" /> 74 75 <TextView 76 android:layout_width="50dp" 77 android:layout_height="50dp" 78 android:background="#ff6969" /> 79 80 <TextView 81 android:layout_width="50dp" 82 android:layout_height="0dp" 83 android:layout_weight="1" 84 android:background="#57d978" /> 85 86 <TextView 87 android:layout_width="50dp" 88 android:layout_height="50dp" 89 android:background="#ff6969" /> 90 91 <TextView 92 android:layout_width="50dp" 93 android:layout_height="0dp" 94 android:layout_weight="1" 95 android:background="#57d978" /> 96 97 <TextView 98 android:layout_width="50dp" 99 android:layout_height="50dp" 100 android:background="#ff6969" /> 101 102 <TextView 103 android:layout_width="50dp" 104 android:layout_height="0dp" 105 android:layout_weight="1" 106 android:background="#57d978" /> 107 108 <TextView 109 android:layout_width="50dp" 110 android:layout_height="50dp" 111 android:background="#ff6969" /> 112 113 <TextView 114 android:layout_width="50dp" 115 android:layout_height="0dp" 116 android:layout_weight="1" 117 android:background="#57d978" /> 118 119 <TextView 120 android:layout_width="50dp" 121 android:layout_height="50dp" 122 android:background="#ff6969" /> 123 124 <TextView 125 android:layout_width="50dp" 126 android:layout_height="0dp" 127 android:layout_weight="1" 128 android:background="#57d978" /> 129 130 <TextView 131 android:layout_width="50dp" 132 android:layout_height="50dp" 133 android:background="#ff6969" /> 134 135 <TextView 136 android:layout_width="50dp" 137 android:layout_height="0dp" 138 android:layout_weight="1" 139 android:background="#57d978" /> 140 141 <TextView 142 android:layout_width="50dp" 143 android:layout_height="50dp" 144 android:background="#ff6969" /> 145 146 <TextView 147 android:layout_width="50dp" 148 android:layout_height="0dp" 149 android:layout_weight="1" 150 android:background="#57d978" /> 151 152 <TextView 153 android:layout_width="50dp" 154 android:layout_height="50dp" 155 android:background="#ff6969" /> 156 157 <TextView 158 android:layout_width="50dp" 159 android:layout_height="0dp" 160 android:layout_weight="1" 161 android:background="#57d978" /> 162 163 <TextView 164 android:layout_width="50dp" 165 android:layout_height="50dp" 166 android:background="#ff6969" /> 167 168 <TextView 169 android:layout_width="50dp" 170 android:layout_height="0dp" 171 android:layout_weight="1" 172 android:background="#57d978" /> 173 174 <TextView 175 android:layout_width="50dp" 176 android:layout_height="50dp" 177 android:background="#ff6969" /> 178 179 </LinearLayout> 180</android.support.constraint.ConstraintLayout>

投稿2018/06/25 00:23

Mikan.K

総合スコア14

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

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

sena14

2018/06/29 06:10

遅くなってしまって申し訳ありません。 ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問