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

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

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

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

Q&A

解決済

2回答

12583閲覧

Android Studio2.3でボタンの配置がズレる。

退会済みユーザー

退会済みユーザー

総合スコア0

Android Studio

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

0グッド

0クリップ

投稿2017/03/24 16:15

編集2017/03/25 01:21

イメージ説明イメージ説明
###前提・実現したいこと
一枚目の画像のようにボタンを配置したいのですが、エミュレーターで見ると二枚目の画像のようになってしまいます。
xmlのページでポンの部分をマウスで動かして配置しました。
xmlのページの右上にエラーメッセージでポンのボタンの座標について書かれていましたが消してしまいました。
ログに異常はありませんでした。
activity_main.xml

<?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="com.example.myfirstapp.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/title_janken" android:textAppearance="@android:style/TextAppearance.Large" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintHorizontal_bias="0.038" app:layout_constraintVertical_bias="0.006" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onDuel" android:text="@string/button_showsign" android:textAppearance="@android:style/TextAppearance.Large" tools:layout_editor_absoluteX="136dp" tools:layout_editor_absoluteY="220dp" tools:ignore="MissingConstraints" /> </android.support.constraint.ConstraintLayout>

strings.xml

<resources> <string name="app_name">My FirstApp</string> <string name="title_janken">じゃんけんゲーム</string> <string name="button_showsign">ポン</string> </resources>

activity_main.xml の<Buttonの中に
以下の2行を入れることでエミュレーターでもPreviewどおり中心に配置できました

app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toTopOf="parent"

イメージ説明

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

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

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

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

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

yona

2017/03/24 16:43

画像だけでなく、xmlを追記してください。
退会済みユーザー

退会済みユーザー

2017/03/24 16:49

すみません、忘れていました。
guest

回答2

0

ベストアンサー

私も同じ現象に会いましたが
activity_main.xml の<Buttonの中に
以下の2行を入れることでエミュレーターでもPreviewどおり中心に配置できました

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"

投稿2017/03/24 20:38

ppmo

総合スコア88

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

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

退会済みユーザー

退会済みユーザー

2017/03/25 01:25

やってみたんですけど、ボタンの配置が中央から左にズレました。 画像を質問のところに貼り付けておきます。
ppmo

2017/03/25 01:28

app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" もともとの状態が違ってたらからかもしれません この四行になってました
退会済みユーザー

退会済みユーザー

2017/03/25 01:35

できました、ありがとうございます。
guest

0

正直、ConstraintLayoutはお勧めできないです。
このGUI操作だけでレイアウトファイルを自動作成してくれる機能ですが、一部分で使ってしまうと、xmlを使った微調整が困難になってしまいます。

そのため、RelativeLayoutを使うことをオススメします。

投稿2017/03/24 17:15

yona

総合スコア18155

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

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

退会済みユーザー

退会済みユーザー

2017/03/25 01:31

レイアウトを変える方法を教えてください。 お願いします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問