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

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

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

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

Q&A

解決済

1回答

19955閲覧

AndroidStudioのエラーが解決できません。

退会済みユーザー

退会済みユーザー

総合スコア0

Android Studio

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

0グッド

0クリップ

投稿2017/03/25 13:44

次のエラーが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にしたのですが、解消されません。

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

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

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

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

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

guest

回答1

0

ベストアンサー

エラーメッセージをを要約すると以下のような内容と思います。

「水平制約・垂直制約をつけておかないとレイアウトエディター上の見た目の配置と実行時の配置が不一致になるので制約をつけてください。制約を付けるには(本件では左右の)端を一旦別のウィジェットの境界にくっつけてからドラッグすればいいです」

XMLをみると問題のTextViewとRadioGroupには、

layout_constraintLeft_toLeftOf、
layout_constraintRight_toLeftOf

がなくこれが水平制約だと思うので前述の操作によりこれらの制約を付けることができればエラーが解消されレイアウトが期待通りになる気がします。

間違ってたらご容赦。

投稿2017/03/25 15:04

KSwordOfHaste

総合スコア18394

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

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

退会済みユーザー

退会済みユーザー

2017/03/25 16:03

解決しました。ありがとうございます。 ちゃんと書いてありましたね。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問