单击 SearchView 后移动 RecyclerView
Move RecyclerView After Click on SearchView
在我的程序中,我使用带有 recyclerview 的搜索视图,在 xml 中,搜索视图位于回收器视图上方,现在我的问题是当我单击搜索视图位置时,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" />
您应该使用 LinearLayout
,其中有 vertical orientation
。
如果您想使用 RelativeLayout
,只需在 xml 视图中添加该行即可。
android:layout_below="@+id/view_id" //Positions the top edge of this view below the given anchor view ID.
But I think you have used ConstraintLayout. Because only this Layout creates
this kind of issue. So it will be better to skip this layout if you
use it.
要么去掉recyclerView
的固定高度
android:layout_height="wrap_content"
或(更好)删除这个
app:layout_constraintBottom_toBottomOf="parent"
约束布局无法解析 dp 中的固定高度和父级底部上方的高度(有点循环依赖性)
在我的程序中,我使用带有 recyclerview 的搜索视图,在 xml 中,搜索视图位于回收器视图上方,现在我的问题是当我单击搜索视图位置时,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" />
您应该使用 LinearLayout
,其中有 vertical orientation
。
如果您想使用 RelativeLayout
,只需在 xml 视图中添加该行即可。
android:layout_below="@+id/view_id" //Positions the top edge of this view below the given anchor view ID.
But I think you have used ConstraintLayout. Because only this Layout creates this kind of issue. So it will be better to skip this layout if you use it.
要么去掉recyclerView
android:layout_height="wrap_content"
或(更好)删除这个
app:layout_constraintBottom_toBottomOf="parent"
约束布局无法解析 dp 中的固定高度和父级底部上方的高度(有点循环依赖性)