「Android Studio 3.0.1」でデザインプレビューで表示されるテキストと、エミュレーター(もしくは実機デバッグ)で表示されるテキスト内容が異なる

IDEAndroid Studio

確認項目

 状態:解決済  閲覧数:3,153  投稿日:2018-03-17  更新日:2018-03-17

tools:text


activity_main.xmlの「TextView」に「android:text」と「tools:text」が設定されていないか確認する
・設定されている場合は、両方に記述する内容を一致させる

実際に遭遇したケース1

 閲覧数:387 投稿日:2018-03-17 更新日:2018-04-24

「デザインプレビュー」では「Hello Android!」、「エミュレータ」「実機」では「Hello World!」と表示されるケース


▼\app\src\main\res\layout\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="tokyo.w3c.android0.app20180302.MainActivity">

   <TextView
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:text="Hello World!"
       android:textSize="36sp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:layout_constraintTop_toTopOf="parent"
       tools:text="Hello Android!" />

</android.support.constraint.ConstraintLayout>


「デザインプレビュー」「エミュレータ」「実機」全てにおいて「Hello Android!」と表示されるケース


▼\app\src\main\res\layout\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="tokyo.w3c.android0.app20180302.MainActivity">

   <TextView
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:text="Hello Android!"
       android:textSize="36sp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:layout_constraintTop_toTopOf="parent"
       tools:text="Hello Android!" />

</android.support.constraint.ConstraintLayout>


実際に遭遇したケース2

 閲覧数:394 投稿日:2018-04-24 更新日:2018-04-25

問題発生


「デザインプレビュー」では「ボタン」表示されるのに、「実機デバッグ」する際は「ボタン」が表示されない

ポイント


「デザインプレビュー」内容は、「実機」表示内容と必ずしも一致するわけではない

最初に実行すること


警告もしくはエラーが表示されているはずなので、まず最初に確認する
・右上角に「Show Warnings and Errors」アイコンがあるのでクリック
This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints 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.

このビューは制約されていません。 制約を追加しない限り、実行時に(0,0)にジャンプします。レイアウトエディタを使用すると、ウィジェットをキャンバス上の任意の場所に配置することができ、designtime属性(layout_editor_absoluteXなど)で現在の位置を記録できます。 。 これらの属性は実行時に適用されないため、デバイス上でレイアウトをプッシュすると、ウィジェットはエディタに表示されていない別の場所に表示されることがあります。 これを修正するには、エッジ接続からドラッグして、ウィジェットが水平と垂直の両方の制約を持っていることを確認します。

原因


制約が足りなかったことが判明

対応案


2種類
・A.手動で制約付与
・B.自動で制約付与

A.手動で制約付与
・エラーとなっているウィジェットの左端をドラッグして、画面左端へくっつければ良い
・左端へドラッグ後、再度希望位置へドラッグ
・垂直指定も付与
・この方法の問題点は、レイアウトによっては期待した通りのレイアウトとならない場合がある(中央配置したウィジェットからの位置のみ指定したい場合)

B.自動で制約付与
・Infer Constraintsボタンを押す
リンク先の「Infer Constraintsボタン」アイコンは古いため注意が必要。現在のアイコンとは異なる

注意事項
・何れの場合でも、エラー表示が消えることを必ず確認する
※エラー表示が消えるまで繰り返す

コード例


修正前の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=".MainActivity">

   <TextView
       android:id="@+id/timeText"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="00:00:00"
       android:textSize="60sp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:layout_constraintTop_toTopOf="parent"
       tools:text="00:00:00" />

   <Button
       android:id="@+id/start"
       android:layout_width="88dp"
       android:layout_height="wrap_content"
       android:text="start"
       tools:layout_editor_absoluteX="131dp"
       tools:layout_editor_absoluteY="486dp" />

   <Button
       android:id="@+id/stop"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginEnd="32dp"
       android:layout_marginStart="32dp"
       android:layout_marginTop="32dp"
       android:text="stop"
       app:layout_constraintEnd_toStartOf="@+id/reset"
       app:layout_constraintHorizontal_bias="1.0"
       app:layout_constraintStart_toEndOf="@+id/start"
       app:layout_constraintTop_toBottomOf="@+id/timeText" />

   <Button
       android:id="@+id/reset"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="reset"
       tools:layout_editor_absoluteX="376dp"
       tools:layout_editor_absoluteY="485dp" />

</android.support.constraint.ConstraintLayout>


A案で修正後の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=".MainActivity">

   <TextView
       android:id="@+id/timeText"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="00:00:00"
       android:textSize="60sp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:layout_constraintTop_toTopOf="parent"
       tools:text="00:00:00" />

   <Button
       android:id="@+id/start"
       android:layout_width="96dp"
       android:layout_height="48dp"
       android:layout_marginEnd="32dp"
       android:layout_marginTop="30dp"
       android:text="start"
       app:layout_constraintEnd_toStartOf="@+id/stop"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toBottomOf="@+id/timeText" />

   <Button
       android:id="@+id/stop"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginEnd="32dp"
       android:layout_marginStart="32dp"
       android:layout_marginTop="32dp"
       android:text="stop"
       app:layout_constraintEnd_toStartOf="@+id/reset"
       app:layout_constraintHorizontal_bias="1.0"
       app:layout_constraintStart_toEndOf="@+id/start"
       app:layout_constraintTop_toBottomOf="@+id/timeText" />

   <Button
       android:id="@+id/reset"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginStart="33dp"
       android:layout_marginTop="32dp"
       android:text="reset"
       app:layout_constraintStart_toEndOf="@+id/stop"
       app:layout_constraintTop_toBottomOf="@+id/timeText" />

</android.support.constraint.ConstraintLayout>


B案で修正後の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=".MainActivity">

<TextView
android:id="@+id/timeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00:00"
android:textSize="60sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="00:00:00" />

<Button
android:id="@+id/start"
android:layout_width="86dp"
android:layout_height="wrap_content"
android:layout_marginEnd="150dp"
android:layout_marginStart="143dp"
android:layout_marginTop="32dp"
android:text="start"
app:layout_constraintEnd_toStartOf="@+id/reset"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/timeText" />

<Button
android:id="@+id/stop"
android:layout_width="86dp"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:text="stop"
app:layout_constraintEnd_toStartOf="@+id/reset"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/start"
app:layout_constraintTop_toBottomOf="@+id/timeText" />

<Button
android:id="@+id/reset"
android:layout_width="86dp"
android:layout_height="wrap_content"
android:layout_marginEnd="136dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:text="reset"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/start"
app:layout_constraintTop_toBottomOf="@+id/timeText" />

</android.support.constraint.ConstraintLayout>



「Android Studio 3.0.1」でプロジェクトを選択するためには? 最初に「現在開いているプロジェクト」を閉じる必要がある

Android Studio で、ソースコードが改行できない



類似度ページランキング
順位 ページタイトル抜粋
1 「Android Studio 3.0.1」でデザインプレビューで表示されるテキストと、エミュレーター(もしくは実機デバッグ)で表示されるテキスト内容が異なる 71
2 「Android Studio 3.0.1」で、デザインプレビュー画面が表示されない。「waiting build for finish」が終わらない 43
3 Android Studio のデザインプレビューで日本語が××で表示されます 42
4 「Android Studio 3.1.2」で「Propertiesペイン」が表示されない 39
5 Android Studio 3.1.2 で、パレットの「Widgets」内にSpinnerが表示されないため、選択出来ない 38
6 「android compile with 」プルダウン内容が表示されないため、プロジェクト作成完了ボタンをクリックできない 34
7 エミュレータ中身を「ファイル・エクスプローラ」で確認したいのに、何も表示されない 34
8 「Android Studio 3.1.2」でプロジェクト削除するためには、物理的にキーボードの「Delete」キーを押す必要がある 33
9 Android用と思われるLogCatビューが、LogCat(使用すべきではありません)と表示されている理由 33
10 Android Studio の Designプレビュー で、ウィジェットをドラッグ配置できない 33
11 「Android Studio 3.1.2」のデザインタブで、RadioGroupの中にRadioButtonを配置出来ない 32
12 Android Studio の Designプレビュー で、ウィジェットを中央に配置 31
13 エミュレータ利用時、「adb shell」ルートパスが、Windows全体ではどの位置にあるか知りたい 31
14 Android Studio で、「パッケージ名」変更 30
15 「Android Studio 3.0.1」でプロジェクトを選択するためには? 最初に「現在開いているプロジェクト」を閉じる必要がある 30
16 Androidエミュレータで、日本語入力したい 29
17 Android Studio で、ソースコードが改行できない 29
18 Androidエミュレータで、PCキーボード入力を有効にしたい 29
19 「Android Studio 3.1.2」で「Translations Editor」を表示 29
20 Android Studio で、エラーメッセージをコピー 28
2024/5/19 8:07 更新
週間人気ページランキング / 5-12 → 5-18
順位 ページタイトル抜粋 アクセス数
1 インポートされた ★★ は見つかりません | エラー 63
2 この行に複数マーカーがあります | エラー(エラー) 45
3 いくつかのプロジェクトは、ワークスペース・ディレクトリーにすでに存在するため、インポートできません | エラー 31
4 public 型 ★★ はそれ独自のファイル内に定義されなければなりません | エラー 27
5 ○○は解決できないか、フィールドではありません | エラー(エラー) 16
6 プラグイン "org.eclipse.ui.workbench" からのコードの起動で問題が発生しました | エラー(エラー) 12
7 Androidエミュレータで、PCキーボード入力を有効にしたい | エミュレータ(環境構築) 11
7 キーバインドの競合が発生しました。 通常のアクセラレーター操作を妨げる可能性があります。 | エラー(エラー) 11
7 「Android Studio 3.0.1」で、デザインプレビュー画面が表示されない。「waiting build for finish」が終わらない | Android Studio(IDE) 11
8 ★★ を型に解決できません | エラー(エラー) 9
9 Android Studio で、ソースコードが改行できない | Android Studio(IDE) 7
10 Android FAQ 5
10 インポートされた java.io は見つかりません | エラー(エラー) 5
11 横方向レイアウトで「android:layout_weight」を使用する際、「android:layout_width」を"0dp"にしないとどうなるの? | layout_weight(レイアウト) 3
11 Eclipseが起動しない … ユーザ操作は待機中です | Eclipse(IDE) 3
11 Eclipse で「プロジェクト名」「パッケージ名」を変更する方法 | Eclipse(IDE) 3
11 ファイルのパスをコピーする方法と結果は、右クリックする場所で異なる | Android Studio(IDE) 3
11 エミュレーター画面表示を大きくしたい | エミュレータ(環境構築) 3
12 インポートされたRは見つかりません | エラー(エラー) 2
12 既存プロジェクトがインポート出来ない | プロジェクト(環境構築) 2
2024/5/19 1:01 更新