Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 单击SearchView后移动RecyclerView_Android_Xml_Android Layout_Android Studio_Searchview - Fatal编程技术网

Android 单击SearchView后移动RecyclerView

Android 单击SearchView后移动RecyclerView,android,xml,android-layout,android-studio,searchview,Android,Xml,Android Layout,Android Studio,Searchview,在我的程序中,我使用了一个带有recyclerview的搜索视图,在xml中,搜索视图位于recycler视图上方。现在我的问题是,当我单击搜索视图位置时,recyclerview的位置会上升并放置在搜索视图上 我使用ConstraintLayout,如果我更改项目布局连接,按钮也会向上 XML: <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/

在我的程序中,我使用了一个带有recyclerview的搜索视图,在xml中,搜索视图位于recycler视图上方。现在我的问题是,当我单击搜索视图位置时,recyclerview的位置会上升并放置在搜索视图上

我使用ConstraintLayout,如果我更改项目布局连接,按钮也会向上

XML:

<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.user.classmanager.StudentList"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_StudentList"
    android:layout_width="0dp"
    android:layout_height="56dp"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme"
    tools:layout_constraintTop_creator="1"
    tools:layout_constraintRight_creator="1"
    app:layout_constraintRight_toRightOf="parent"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button_StudentList"
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:text="B"
    app:layout_constraintBottom_toBottomOf="@+id/searchView_StudentList"
    app:layout_constraintHorizontal_bias="0.307"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toLeftOf="@+id/searchView_StudentList"
    app:layout_constraintTop_toTopOf="@+id/searchView_StudentList"
    app:layout_constraintVertical_bias="1.0"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintTop_creator="1" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view_StudentList"
    android:layout_width="370dp"
    android:layout_height="450dp"
    android:layout_marginBottom="0dp"
    android:layout_marginEnd="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginStart="5dp"
    android:layout_marginTop="8dp"
    android:paddingLeft="7dp"
    android:paddingRight="7dp"
    android:paddingTop="22dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/searchView_StudentList"
    app:layout_constraintVertical_bias="0.371"
    tools:layout_constraintBottom_creator="1"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintRight_creator="1" />

<SearchView
    android:id="@+id/searchView_StudentList"
    android:layout_width="300dp"
    android:layout_height="0dp"
    android:layout_marginEnd="7dp"
    android:layout_marginRight="7dp"
    android:layout_marginTop="13dp"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/toolbar_StudentList"
    tools:layout_constraintRight_creator="1"
    tools:layout_constraintTop_creator="1" />


您应该使用
线性布局
,它具有
垂直方向

如果要使用
RelativeLayout
,只需在xml视图中添加该行即可

android:layout_below="@+id/view_id" //Positions the top edge of this view below the given anchor view ID.
但我想你已经用过了。因为只有这样的布局才能创建 这类问题。因此,如果您愿意,最好跳过此布局 使用它


移除
回收视图的固定高度

  android:layout_height="wrap_content" 
或者(更好)删除此项

  app:layout_constraintBottom_toBottomOf="parent"

Constraint layout无法解析dp中以及父级底部上方的固定高度(有点像循环依赖关系)

发布活动xml。。我会解决的..发布xml文件..你现在可以看到@Santanu Sur@AL Teganiyes我使用ConstraintLayout,但是你能告诉我它有什么问题吗@Shamsul Arafin Mahtab真的谢谢你我的问题是解决(第二种方法更好),但是有一个问题,现在很少移动,这正常吗@Santanu Surrough提出了一个很难回答的问题,从逻辑上讲,这应该是可行的,我怀疑它不会像你期望的那样起作用……但如果你遇到任何问题……请随时更新:)@nimakhali