Android layout_below не отображается - PullRequest
1 голос
/ 11 июля 2020

Я пытаюсь разместить свой RecyclerView так, чтобы он находился ниже моего AppBarLayout, однако атрибут layout_below не распознается студией android? Не отображается при автозаполнении.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".Fragment.SearchFragment">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bar"
        android:background="?android:attr/windowBackground">

    <androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        android:id="@+id/toolbar">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_search_light"
        android:layout_marginRight="10dp"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/search_bar"
        android:background="@android:color/transparent"
        android:hint="Search..."
        android:layout_marginStart="10dp"
        android:layout_marginLeft="10dp"/>

    </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

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

</FrameLayout>

Ответы [ 4 ]

0 голосов
/ 11 июля 2020

вам нужен макет, такой как ConstraintLayout, RelativeLayout и LinearLayout.

пример:

ConstraintLayout:

   <?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bar"
        android:background="?android:attr/windowBackground">

        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:attr/windowBackground"
            android:id="@+id/toolbar">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_search_light"
                android:layout_marginRight="10dp"/>

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/search_bar"
                android:background="@android:color/transparent"
                android:hint="Search..."
                android:layout_marginStart="10dp"
                android:layout_marginLeft="10dp"/>

        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        app:layout_constraintTop_toBottomOf="@id/bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/recycler_view" />


    </androidx.constraintlayout.widget.ConstraintLayout>

</FrameLayout>

RelativeLayout:

 <?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bar"
        android:background="?android:attr/windowBackground">

        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:attr/windowBackground"
            android:id="@+id/toolbar">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_search_light"
                android:layout_marginRight="10dp"/>

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/search_bar"
                android:background="@android:color/transparent"
                android:hint="Search..."
                android:layout_marginStart="10dp"
                android:layout_marginLeft="10dp"/>

        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_below="@id/bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/recycler_view" />


    </RelativeLayout>

LinearLayout:

 <?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bar"
        android:background="?android:attr/windowBackground">

        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:attr/windowBackground"
            android:id="@+id/toolbar">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_search_light"
                android:layout_marginRight="10dp"/>

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/search_bar"
                android:background="@android:color/transparent"
                android:hint="Search..."
                android:layout_marginStart="10dp"
                android:layout_marginLeft="10dp"/>

        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

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


    </LinearLayout>
 
    
    </FrameLayout>
0 голосов
/ 11 июля 2020

Это неверно. RecyclerView никогда не должен go под AppBarLayout. Что вам следует сделать, так это убедиться, что между RecyclerView и AppbarLayout имеется достаточный запас

0 голосов
/ 11 июля 2020

Пожалуйста, измените ваш макет, как показано ниже. Используется LinearLayout со свойством android:orientation="vertical" вместо FrameLayout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".Fragment.SearchFragment"
    android:orientation="vertical">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bar"
        android:background="?android:attr/windowBackground">

        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:attr/windowBackground"
            android:id="@+id/toolbar">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_search_light"
                android:layout_marginRight="10dp"/>

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/search_bar"
                android:background="@android:color/transparent"
                android:hint="Search..."
                android:layout_marginStart="10dp"
                android:layout_marginLeft="10dp"/>

        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

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

</LinearLayout>
0 голосов
/ 11 июля 2020
• 1000
...