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

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

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

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

Java

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

Android Studio

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

Q&A

解決済

1回答

1153閲覧

AndroidStudioのレイアウト、ConstraintLayoutの比重を変えたいのですが。。

tanaka_hana

総合スコア19

XML

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

Java

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

Android Studio

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

0グッド

0クリップ

投稿2018/12/09 12:15

前提・実現したいこと

AndroidStudioで、2つの写真を画面の半分ずつ縦に並べて、その要素の中にそれぞれボタンを表示させたい。(相対的に位置を決めたいため)

発生している問題・エラーメッセージ

ConstraintLayoutを2つ同階層に並べてその中にButtonを作り、位置を決めました。
ただ、赤線がひかれている上に、各ConstraintLayoutにandroid:layout_weight="1"を指定してもConstraintLayout要素は分割されていませんでした。

該当のソースコード

xml

1<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:app="http://schemas.android.com/apk/res-auto" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 tools:context=".AirportActivity"> 7 8 <android.support.constraint.ConstraintLayout 9 android:background="@drawable/narita_airport" 10 android:layout_width="match_parent" 11 android:layout_height="match_parent" 12 android:layout_weight="1"> 13 14 <Button 15 android:text="@string/tv_airport_name_narita" 16 android:layout_width="wrap_content" 17 android:layout_height="wrap_content" /> 18 19 </android.support.constraint.ConstraintLayout> 20 <android.support.constraint.ConstraintLayout 21 android:layout_width="match_parent" 22 android:layout_height="match_parent" 23 android:background="@drawable/haneda_airport" 24 android:layout_weight="1"> 25 26 <Button 27 android:text="@string/tv_airport_name_haneda" 28 android:layout_width="wrap_content" 29 android:layout_height="wrap_content" /> 30 31 32 </android.support.constraint.ConstraintLayout> 33 34</android.support.constraint.ConstraintLayout>

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

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

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

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

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

guest

回答1

0

ベストアンサー

ガイドラインを引けばいいのではないでしょうか。下記のように記述すると、上下半分ずつに分割するようにガイドラインが引かれます(0.5は50%を意味します)。このガイドラインを基準にして制約をつければ、目的を達せられると思います。

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".activity.MainActivity"> <android.support.constraint.Guideline android:id="@+id/guideline" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent="0.5" /> </android.support.constraint.ConstraintLayout>

投稿2018/12/09 12:50

keicha_hrs

総合スコア6766

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

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

tanaka_hana

2018/12/09 16:38

返信ありがとうございます。guidelineを利用してうまくできなかったのですが(説明不足で申し訳ないです)、書いていただいたguidelineの方法で中央に配置し、今一度ConstraintLayoutをいじっているとうまく制約ハンドルが動いてくれました!ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問