###前提・実現したいこと
一枚目の画像のようにボタンを配置したいのですが、エミュレーターで見ると二枚目の画像のようになってしまいます。
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"
画像だけでなく、xmlを追記してください。
すみません、忘れていました。
回答2件
あなたの回答
tips
プレビュー