我正在尝试在我的回收器视图上方添加一个Imageview,但回收器视图最终会占据整个屏幕并且不会显示我的图像视图。
<?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:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
tools:context=".AccountFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/blogListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/imageView">
</android.support.v7.widget.RecyclerView>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/acc"
tools:layout_editor_absoluteX="146dp"
tools:layout_editor_absoluteY="86dp" />
</RelativeLayout>
将此属性添加到ImageView:
android:layout_alignParentTop="true"
所以它位于父布局的顶部。 如果您认为这些属性:
tools:layout_editor_absoluteX="146dp"
tools:layout_editor_absoluteY="86dp"
影响ImageView
的位置,那你就错了。
tools
命名空间中的任何属性仅在设计时有效。
所以你不妨删除它们。
您也可以想要将ImageView
水平居中:
android:layout_centerHorizontal="true"
嗨尝试设置这个,因为我检查了它的工作
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_play" />
<android.support.v7.widget.RecyclerView
android:id="@+id/blogListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"></android.support.v7.widget.RecyclerView>
</RelativeLayout>