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

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

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

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

Q&A

解決済

2回答

3573閲覧

Android Studio XMLファイルのErrorについて

Y.R.T

総合スコア42

Android Studio

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

0グッド

0クリップ

投稿2020/09/24 02:57

下記構文で、
Android resource compilation failed
C:\Users\Administrator\AndroidStudioProjects\HelloWorld\app\src\main\res\layout\activity_main.xml:15: AAPT: error: junk after document element.

C:\Users\Administrator\AndroidStudioProjects\HelloWorld\app\src\main\res\layout\activity_main.xml: AAPT: error: file failed to compile.

のErrorが出ます。
どのようにして修正したらよいでしょうか?

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.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:id="@+id/btSave" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#A1A9BA" android:orientation="vertical" tools:context=".MainActivity" android:inputTypt="text"/> <EditText android:id="@+id/etinput" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="25dp" android:lauyout_marginTop="5dp" android:background="#ffffff" android:inputType="text"/> <ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#df7401" android:orientation="horizontal"> <CheckBox android:id="@+id/cbDrink" android:layout_width="wrap_content" android:layout_heigt="wrap_content" android:layout_marginRight="25dp" android:background="#ffffff" android:text="@string/cb_drink"/> <CheckBox android:id="@+id/cbFood" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cb_food"/> </ConstraintLayout> <Button android:id="@+id/btSave" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/bt_save" tools:layout_editor_absoluteX="-7dp" tools:layout_editor_absoluteY="66dp" /> </androidx.constraintlayout.widget.ConstraintLayout> ```

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

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

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

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

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

guest

回答2

0

xml

1<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 6 android:id="@+id/btSave" 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 android:background="#A1A9BA" 10 android:orientation="vertical" 11 tools:context=".MainActivity" 12 android:inputTypt="text"/>

タイプミスでなければ、最後が「/>」になっているので、ConstraintLayoutのタグを閉じてしまっているからではないですか。

投稿2020/09/24 11:27

katsuko

総合スコア3491

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

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

0

ベストアンサー

ConstraintLayout を使用している場合、子の要素に制約をつけなければなりません。
以下のようなコードを各Viewに指定してあげる必要があります。

xml

1 app:layout_constraintStart_toStartOf="parent" 2 app:layout_constraintEnd_toEndOf="parent" 3 app:layout_constraintTop_toTopOf="parent" 4 app:layout_constraintBottom_toBottomOf="parent"

特にこったレイアウトではなくても良い場合、ConstraintLayoutをLinearLayoutに変更すると縦並び、もしくは横並びのレイアウトに変更が可能です。

参考URL: https://techacademy.jp/magazine/4455

投稿2020/09/24 08:39

pg0084

総合スコア100

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

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

Y.R.T

2020/09/24 10:19

2行目が<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" と自動的になっていたのですがこれを、LinearLayoutに変更すれば よいのですか?
pg0084

2020/09/24 13:28

`<androidx.constraintlayout.widget.ConstraintLayout`の部分を`<LinearLayout`に変更で大丈夫かと思います。 ConstraintLayutはレイアウト生成時に自動でなりますが、処理も重く複雑なレイアウトを作るのに向いているため、単純なレイアウトであればLinearLayoutで大丈夫です。
Y.R.T

2020/09/24 23:15

ありがとうございます。 LinearLayoutに変更してみます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問