Android Studio - элементы в эмуляторе не отображаются - PullRequest
0 голосов
/ 10 июля 2020

Я сейчас застрял, пытаясь понять, почему мои кнопки RecycleView и Add не отображаются в моем эмуляторе при запуске, но они отображаются на панели предварительного просмотра моей IDE. Я попытался включить системный интерфейс и обойти это, но он тоже не отображается, когда я это делаю. Что могло быть причиной этого?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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">

    <Button
        android:id="@+id/btnAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="681dp"
        android:layout_marginEnd="0dp"
        android:layout_marginBottom="0dp"
        android:text="Add" />

    <EditText
        android:id="@+id/etItem"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="-2dp"
        android:layout_marginTop="683dp"
        android:layout_marginEnd="2dp"
        android:layout_marginBottom="3dp"
        android:layout_toStartOf="@+id/btnAdd"
        android:autofillHints=""
        android:ems="10"
        android:hint="@string/add_an_item_here" />

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/etItem"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="0dp"
        android:layout_marginTop="0dp"
        android:layout_marginEnd="0dp"
        android:layout_marginBottom="0dp" />

</RelativeLayout>

Emulator

IDE

Ответы [ 2 ]

1 голос
/ 11 июля 2020

Удалите свойства «android: layout_marginTop» и «android: layout_alignParentTop» из Button или EditText. Пожалуйста, проверьте код ниже:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:text="Add" />

<EditText
android:id="@+id/etItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_marginLeft="0dp"
android:layout_marginBottom="3dp"
android:layout_toStartOf="@+id/btnAdd"
android:layout_toLeftOf="@+id/btnAdd"
android:autofillHints=""
android:ems="10"
android:hint="Enter value" />

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/etItem"
android:layout_centerHorizontal="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="0dp" />

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:text="Add" />

<EditText
android:id="@+id/etItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_marginLeft="0dp"
android:layout_marginBottom="3dp"
android:layout_toStartOf="@+id/btnAdd"
android:layout_toLeftOf="@+id/btnAdd"
android:autofillHints=""
android:ems="10"
android:hint="Enter value" />

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/etItem"
android:layout_centerHorizontal="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="0dp" />

</RelativeLayout>
1 голос
/ 10 июля 2020

Попробуйте именно это в файле макета xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/btnAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:text="Add" />

    <EditText
        android:id="@+id/etItem"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toStartOf="@+id/btnAdd"
        android:autofillHints=""
        android:ems="10"
        android:hint="THIS IS HINT" />

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/etItem"/>

</RelativeLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...