为什么不显示在回收站视图顶部的图像视图?

问题描述 投票:0回答:5

我正在尝试将图像视图作为横幅添加到回收者视图的顶部。因此在某些情况下,我可以隐藏(View.GONE)或显示该横幅图像视图(View.VISIBLE)。但是问题是,即使我在图像视图xml上设置了android:visibility="visible",横幅图像视图也永远不会在运行应用程序时显示。

如您所见,我的图像视图带有红色背景,但是该红色背景图像视图不会显示

如何解决这个问题?

我的片段中的布局是这样的

enter image description here

这是xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
                                                   tools:context=".Fragments.Search.SearchKeywordResultFragment"
                                                   android:id="@+id/constraintLayout_search_keyword_fragment">


    <androidx.recyclerview.widget.RecyclerView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:scrollbars="vertical"
            tools:listitem="@layout/item_general_event"
            android:id="@+id/recyclerView_keyword_search_result"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"/>

    <ImageView
            android:id="@+id/imageView_banner_search_keyword"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:background="#E91E63"
            android:visibility="visible"
            app:layout_constraintBottom_toBottomOf="@+id/recyclerView_keyword_search_result"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            tools:src="@tools:sample/avatars[3]" />


</androidx.constraintlayout.widget.ConstraintLayout>
android android-recyclerview android-imageview
5个回答
0
投票

只需将Recycler的TopToTop约束更改为Image视图的ID,然后将其更改为TopToBottom。为此,您还需要先声明imageview,以便能够解决其ID。同时指定横幅宽度:match_parent

<ImageView
        android:id="@+id/imageView_banner_search_keyword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:background="#E91E63"
        android:visibility="visible"
   app:layout_constraintBottom_toBottomOf="@+id/recyclerView_keyword_search_result"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        tools:src="@tools:sample/avatars[3]" />

<androidx.recyclerview.widget.RecyclerView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:scrollbars="vertical"
        tools:listitem="@layout/item_general_event"
        android:id="@+id/recyclerView_keyword_search_result"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="imageView_banner_search_keyword" app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"/>

0
投票

我已经使用过类似的方法,可以尝试一下,它正在运行

<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:shimmer="http://schemas.android.com/apk/res-auto"
android:background="@color/darkgrey"
tools:context=".ui.ProductList.ProductListFragment">

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center_vertical"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="@dimen/padding_10"
        android:text=" Select an item closest to your desired search"
        android:textSize="16sp"
        android:textColor="@color/black"/>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/product_list_recyclerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:layout_marginBottom="60dp"
            android:scrollbars="vertical" />
        </LinearLayout>
    </ScrollView>


    <android.support.v4.view.ViewPager
        android:id="@+id/list_pager"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_alignParentBottom="true"
        android:layout_gravity="end"
        android:visibility="invisible"
        android:background="@color/white"
        android:gravity="bottom|center"
    />
</RelativeLayout>

在viewpager上,您可以使用Imageview。


0
投票

因为在imageView上有代码行tools:src="@tools:sample/avatars[3]"工具功能,它将仅在android布局编辑器上显示。尝试从位图或从app:srcCompat="@drawable/{your_drawable_or_mipmap_data_file}"]处的drawable更改为真实图像


0
投票

尝试在ImageView上设置android:adjustViewBounds="true"android:scaleType="fitCenter"


0
投票

布局固定。您的底部回收视图方法存在问题。您正在使用tools

© www.soinside.com 2019 - 2024. All rights reserved.