次のエラーがactivity_main.xmlのTextViewとRadioGroupで出ます。
This view is not constrained horizontally: at runtime it will jump to the left unless you add a horizontal constraint less... (Ctrl+F1)
The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with designtime attributes (such as layout_editor_absoluteX.) These attributes are not applied at runtime, so if you push your layout on a device, the widgets may appear in a different location than shown in the editor. To fix this, make sure a widget has both horizontal and vertical constraints by dragging from the edge connections.
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.0" app:layout_constraintVertical_bias="0.0" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="80dp" android:layout_marginTop="60dp" android:onClick="onDuel" android:text="@string/button_showsign" 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_constraintVertical_bias="0.798" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="30dp" android:gravity="center" android:text="@string/start_janken" app:layout_constraintBottom_toTopOf="@+id/button" tools:layout_editor_absoluteX="124dp" /> <RadioGroup android:layout_width="353dp" android:layout_height="146dp" android:layout_marginBottom="46dp" android:orientation="horizontal" app:layout_constraintBottom_toTopOf="@+id/textView" tools:layout_editor_absoluteX="4dp"> <RadioButton android:id="@+id/radioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="4dp" android:layout_weight="1" android:text="@string/goo" /> <RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="4dp" android:layout_weight="1" android:text="@string/choki" /> <RadioButton android:id="@+id/radioButton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="4dp" android:layout_weight="1" android:text="@string/paa" /> </RadioGroup> </android.support.constraint.ConstraintLayout>
strings.xml
<resources> <string name="app_name">My FirstApp</string> <string name="title_janken">じゃんけんゲーム</string> <string name="button_showsign">ポン</string> <string name="goo">グー</string> <string name="choki">チョキ</string> <string name="paa">パー</string> <string name="start_janken">じゃんけん・・・</string> </resources>
MainAcrivity.java
package com.example.myfirstapp; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onDuel(View view){ Toast.makeText(this, "私はグー", Toast.LENGTH_SHORT).show(); } }
一枚目の画像にしたいのですが、二枚目の画像のようになってしまいます。
layout_editor_absoluteXの値をいじったり、
gravityをcenterにしたのですが、解消されません。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/03/25 16:03