Java 无法在RelativeLayout中查看带有RecyclerView的ImageView
我正在尝试创建一个简单的图像库,使用RecyclerView在底部显示缩略图,并在ImageView中显示上面的大型/详细照片 问题是-显示并创建了带有缩略图的RecyclerView-但是,即使对背景进行硬编码,也不会显示大型/详细图像。我认为这是一个与XML相关的问题,但我似乎无法发现问题所在 如有任何建议,我们将不胜感激 XML:Java 无法在RelativeLayout中查看带有RecyclerView的ImageView,java,android,xml,android-layout,Java,Android,Xml,Android Layout,我正在尝试创建一个简单的图像库,使用RecyclerView在底部显示缩略图,并在ImageView中显示上面的大型/详细照片 问题是-显示并创建了带有缩略图的RecyclerView-但是,即使对背景进行硬编码,也不会显示大型/详细图像。我认为这是一个与XML相关的问题,但我似乎无法发现问题所在 如有任何建议,我们将不胜感激 XML: 将相对布局更改为线性布局解决了该问题 从相对布局更改为线性布局解决了问题 问题是您正在将RecyclerView设置为match\u parent。这与您的图像
将
相对布局更改为线性布局解决了该问题 从相对布局
更改为线性布局
解决了问题 问题是您正在将RecyclerView
设置为match\u parent
。这与您的图像视图重叠
因此,将布局更改为
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:background="@drawable/mms_img1"
android:scaleType="centerCrop" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="28dp"
android:id="@+id/rv_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/detail_photo"
android:layout_below="@id/detail_photo"
android:background="@color/black_color"
/>
</RelativeLayout>
问题在于您正在将RecyclerView
设置为match\u parent
。这与您的图像视图重叠
因此,将布局更改为
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:background="@drawable/mms_img1"
android:scaleType="centerCrop" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="28dp"
android:id="@+id/rv_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/detail_photo"
android:layout_below="@id/detail_photo"
android:background="@color/black_color"
/>
</RelativeLayout>
这对你很有用
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black">
<ImageView
android:id="@+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:background="@drawable/placeholder"
android:scaleType="centerCrop" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_images"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/detail_photo"
android:background="@color/red_500" />
这对你有用
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black">
<ImageView
android:id="@+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:background="@drawable/placeholder"
android:scaleType="centerCrop" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_images"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/detail_photo"
android:background="@color/red_500" />
虽然这个代码片段可以解决这个问题,但它确实有助于提高文章的质量。请记住,您将在将来回答读者的问题,而这些人可能不知道您的代码建议的原因。虽然此代码片段可以解决问题,但确实有助于提高您文章的质量。请记住,您将在将来回答读者的问题,这些人可能不知道您的代码建议的原因。
<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MMSGallery">
<ImageView
android:id="@+id/detail_photo"
android:background="@mipmap/ic_launcher"
android:adjustViewBounds="true"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:layout_margin="2dp"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_images"
android:layout_below="@+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_color" />
</RelativeLayout>