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

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

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

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

Android

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

Q&A

解決済

2回答

464閲覧

<Androidアプリ開発>ConstraintLayoutでのレイアウト指定方法について教えてください

m_s

総合スコア51

XML

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

Android

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

0グッド

0クリップ

投稿2019/12/08 16:30

編集2019/12/09 16:41

下記のように、recyclerView(id=my_recycler_view)の中にbuttonなどをまとめたid=layout_subが入っている状態なのですが、それをrecyclerView(id=my_recycler_view)の下にid=layout_subを配置するようにしたいのですが、
例えば、下記のようにid=layout_subに制約を指定しても中々うまくいきません。
解決方法を教えていただけると幸いです。

xml

1 app:layout_constraintTop_toBottomOf="@+id/my_recycler_view" 2 app:layout_constraintVertical_chainStyle="packed"

before↓
イメージ説明

after(イメージ)↓
イメージ説明

現状のソース

xml

1<?xml version="1.0" encoding="utf-8"?> 2 3<android.support.constraint.ConstraintLayout 4 xmlns:android="http://schemas.android.com/apk/res/android" 5 xmlns:app="http://schemas.android.com/apk/res-auto" 6 xmlns:tools="http://schemas.android.com/tools" 7 android:id="@+id/layout_main" 8 android:layout_width="match_parent" 9 android:layout_height="match_parent" 10 tools:context=".TalkFragment"> 11 12 <android.support.v7.widget.RecyclerView 13 android:id="@+id/my_recycler_view" 14 android:layout_width="match_parent" 15 android:layout_height="match_parent" 16 android:scrollbars="vertical" 17 tools:layout_editor_absoluteX="272dp" 18 tools:layout_editor_absoluteY="-16dp"/> 19 20 <android.support.constraint.ConstraintLayout 21 xmlns:android="http://schemas.android.com/apk/res/android" 22 xmlns:app="http://schemas.android.com/apk/res-auto" 23 xmlns:tools="http://schemas.android.com/tools" 24 android:id="@+id/layout_sub" 25 android:layout_width="match_parent" 26 android:layout_height="match_parent" 27 app:layout_constraintTop_toBottomOf="@+id/my_recycler_view" 28 app:layout_constraintVertical_chainStyle="packed" /> 29 30 <Button 31 android:id="@+id/button1" 32 android:layout_width="55dp" 33 android:layout_height="54dp" 34 android:text="カメラ" 35 app:layout_constraintBottom_toBottomOf="parent" 36 app:layout_constraintLeft_toLeftOf="parent" 37 app:layout_constraintTop_toTopOf="parent" 38 app:layout_constraintVertical_bias="1.0" /> 39 40 <Button 41 android:id="@+id/button2" 42 android:layout_width="55dp" 43 android:layout_height="54dp" 44 android:text="画像" 45 app:layout_constraintBottom_toBottomOf="parent" 46 app:layout_constraintLeft_toRightOf="@+id/button1" 47 app:layout_constraintTop_toTopOf="parent" 48 app:layout_constraintVertical_bias="1.0" /> 49 50 <Button 51 android:id="@+id/button3" 52 android:layout_width="wrap_content" 53 android:layout_height="wrap_content" 54 android:text="送信" 55 app:layout_constraintBottom_toBottomOf="parent" 56 app:layout_constraintVertical_bias="0.994" 57 app:layout_constraintLeft_toRightOf="@+id/edittext" /> 58 59 <EditText 60 android:id="@+id/edittext" 61 android:layout_width="180dp" 62 android:layout_height="54dp" 63 android:background="@drawable/edittext_background" 64 app:layout_constraintBottom_toBottomOf="parent" 65 app:layout_constraintLeft_toRightOf="@+id/button2" 66 app:layout_constraintTop_toTopOf="parent" 67 app:layout_constraintVertical_bias="1.0" /> 68 </android.support.constraint.ConstraintLayout> 69 70</android.support.constraint.ConstraintLayout>

12/10 1:40 最新↓
イメージ説明

XML

1<?xml version="1.0" encoding="utf-8"?> 2 3<android.support.constraint.ConstraintLayout 4 xmlns:android="http://schemas.android.com/apk/res/android" 5 xmlns:app="http://schemas.android.com/apk/res-auto" 6 xmlns:tools="http://schemas.android.com/tools" 7 android:id="@+id/layout_main" 8 android:layout_width="match_parent" 9 android:layout_height="match_parent" 10 tools:context=".TalkFragment"> 11 12 <android.support.v7.widget.RecyclerView 13 android:id="@+id/my_recycler_view" 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:scrollbars="vertical" 17 app:layout_constraintTop_toTopOf="parent" 18 app:layout_constraintLeft_toLeftOf="parent"/> 19 20 <android.support.constraint.ConstraintLayout 21 xmlns:android="http://schemas.android.com/apk/res/android" 22 xmlns:app="http://schemas.android.com/apk/res-auto" 23 xmlns:tools="http://schemas.android.com/tools" 24 android:id="@+id/layout_sub" 25 android:layout_width="wrap_content" 26 android:layout_height="wrap_content" 27 app:layout_constraintTop_toBottomOf="@+id/my_recycler_view" 28 app:layout_constraintLeft_toLeftOf="parent" 29 app:layout_constraintBottom_toTopOf="parent" 30 app:layout_constraintVertical_chainStyle="packed" > 31 32 <Button 33 android:id="@+id/button1" 34 android:layout_width="55dp" 35 android:layout_height="54dp" 36 android:text="カメラ" 37 app:layout_constraintBottom_toBottomOf="parent" 38 app:layout_constraintLeft_toLeftOf="parent" 39 app:layout_constraintTop_toTopOf="parent" 40 app:layout_constraintVertical_bias="1.0" /> 41 42 <Button 43 android:id="@+id/button2" 44 android:layout_width="55dp" 45 android:layout_height="54dp" 46 android:text="画像" 47 app:layout_constraintBottom_toBottomOf="parent" 48 app:layout_constraintLeft_toRightOf="@+id/button1" 49 app:layout_constraintTop_toTopOf="parent" 50 app:layout_constraintVertical_bias="1.0" /> 51 52 <Button 53 android:id="@+id/button3" 54 android:layout_width="wrap_content" 55 android:layout_height="wrap_content" 56 android:text="送信" 57 app:layout_constraintBottom_toBottomOf="parent" 58 app:layout_constraintVertical_bias="0.994" 59 app:layout_constraintLeft_toRightOf="@+id/edittext" /> 60 61 <EditText 62 android:id="@+id/edittext" 63 android:layout_width="180dp" 64 android:layout_height="54dp" 65 android:background="@drawable/edittext_background" 66 app:layout_constraintBottom_toBottomOf="parent" 67 app:layout_constraintLeft_toRightOf="@+id/button2" 68 app:layout_constraintTop_toTopOf="parent" 69 app:layout_constraintVertical_bias="1.0" /> 70 </android.support.constraint.ConstraintLayout> 71 72</android.support.constraint.ConstraintLayout>

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

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

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

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

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

jimbe

2019/12/09 05:04

android studio のレイアウトのデザインタブでの表示のお話でしょうか. 確認していませんで個人的な感覚ですが, デザインでの表示は(特に中途半端?な対応の RecyclerView 等は)必ずしも実際の表示と同じとは限らないと考えています. 実機なりエミュレータなりで確認されたほうが確実かと思います.
m_s

2019/12/09 12:54

回答ありがとうございます。 実機で動かしてみたのですが、うまくいかない状況でした.....
guest

回答2

0

ベストアンサー

  • RecyclerViewのwidthとheightがmatch_view(0dpかwrap_contextになるはず)
  • RecyclerViewの親ビューへの成約がない(上と左右にないので親ビューに張り付かない)
  • RecyclerViewに↓があるので削除(絶対位置になるので、端末によって見栄えが変わる)

XML

1tools:layout_editor_absoluteX="272dp" 2tools:layout_editor_absoluteY="-16dp"
  • layout_subのwidthとheightがmatch_view(0dpかwrap_contextになるはず)
  • layout_subの親ビューへの成約がない(下と左右にないので親ビューに張り付かない)

こんなところですかね

投稿2019/12/09 09:52

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

m_s

2019/12/09 16:45

回答ありがとうございます。上記の質問欄の「12/10 1:40 最新」と記載されている箇所以下に教えていただいた内容を反映した画面とコードを記載しております。 >RecyclerViewのwidthとheightがmatch_view(0dpかwrap_contextになるはず) >layout_subのwidthとheightがmatch_view(0dpかwrap_contextになるはず) こちらどちらもwrap_contentで設定したのですが画面のように表示されてしまいうまくいきません...。(0dpだと何も表示されなくなってしまいました。)
guest

0

android:layout_marginBottom="32dp"
(数値はお好みで)
これをRecycleViewのXMLに追記してください
下にスペースができるはずです

たぶん私も同じなのですがDesign画面の編集ではRecycleViewを直接触れない仕様になってますよね?
なんでだろ

投稿2019/12/09 01:13

HRSKT

総合スコア168

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問