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

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

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

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

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

Q&A

解決済

1回答

539閲覧

TableLayoutがエラーになる

退会済みユーザー

退会済みユーザー

総合スコア0

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

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

0グッド

0クリップ

投稿2017/11/01 09:14

編集2017/11/01 09:21

お世話になります。参考書を参考にアプリを作ろうとしているのですが、なぜか9行目の<TableLayoutでエラーがでます。どこがいけないのかヒントでも良いので教えて下さい。エミュレータで起動することは可能です。
エラーメッセージは
Preview timed out while rendering the layout. This typically happnes when there is an infinite loop or unbounded recusion in one of custom views.

環境は Windows7 androidstudio2.3.3
エミュレータはNexusS API24

<?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.lc_22k5.myapplication.MainActivity"> <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" tools:layout_editor_absoluteY="8dp" tools:layout_editor_absoluteX="8dp"> <TableRow android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" tools:layout_editor_absoluteX="163dp" tools:layout_editor_absoluteY="441dp" /> <EditText android:id="@+id/editText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:inputType="textPersonName" android:text="Name" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/save" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/transmit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </TableRow> </TableLayout> </android.support.constraint.ConstraintLayout>

したいことは次のようにしたいです。
textview [ edittext ]
Button Button Button
textview

上みたにしたいです。

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

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

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

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

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

guest

回答1

0

ベストアンサー

ConstraintLayoutとは、配置するコンポーネントに「制約」(Constraint)を設けることでレイアウトを決めるものです。質問のXMLコードだと、TableLayoutには何も「制約」がないのでエラーになります。

このケースだと、

XML

1 <TableLayout 2 android:layout_width="0dp" 3 android:layout_height="wrap_content" 4 android:layout_marginEnd="8dp" 5 android:layout_marginStart="8dp" 6 android:layout_marginTop="8dp" 7 app:layout_constraintEnd_toEndOf="parent" 8 app:layout_constraintStart_toStartOf="parent" 9 app:layout_constraintTop_toTopOf="parent"> 10

こんな感じにすればいいでしょうかね?これは、TableLayoutを上、左、右の3方向を親レイアウト(ここではConstraintLayout)と接続して、それぞれ8dpのマージンを取るような「制約」になっています。マージンを設けたくない(ConstraintLayoutにくっつけたい)なら0dpにすればいいでしょう。

なお、android:layout_widthを0dpとしていますが、ConstraintLayoutに配置するレイアウトにおいて0dpは"match_constraint"という特別な意味があります。機能的には従来のレイアウトにおけるmatch_parent(fill_parentは大分前から非推奨です)と似たようなものですが、ConstraintLayoutではmatch_parentは無効となっていて、その代わりに0dpを設定することになっています。


んー?上記の内容も確かにエラーになるはずだけど、質問に記されているエラーとは意味が違うなあ。なんだそれは?このように書き換えても同じエラーになりますか?

投稿2017/11/03 08:55

編集2017/11/03 09:01
keicha_hrs

総合スコア6766

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

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

keicha_hrs

2017/11/03 09:02

なんか随分速攻でベストアンサーにしていただきましたが、大丈夫ですか?実際に確認してからでも遅くはないのですが・・・。
退会済みユーザー

退会済みユーザー

2017/11/03 09:02

すいません(><)本を読みながらやっているのですが、とりあえず先に進もうと思い進んでしまったので、わかりません。でも、毎回毎回僕の質問に答えて頂いて感謝しています。ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問