Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

android - 为什么不显示位于回收者视图顶部的图像视图?(Why image view located on top of recycler view is not displaying?)

I am trying to add an image view as a banner on top of recycler view.

(我正在尝试将图像视图添加为回收者视图顶部的横幅。)

so in some condition I can hide (View.GONE) or to show that banner image view (View.VISIBLE).

(因此在某些情况下,我可以隐藏(View.GONE)或显示该横幅图像视图(View.VISIBLE)。)

but the problem is, the banner image view will never show when I run the app, even though I have set android:visibility="visible" on the image view xml.

(但是问题是,即使我在图像视图xml上设置了android:visibility="visible" ,横幅图像视图也永远不会在我运行应用程序时显示。)

as you can see, I have image view with red background, but that red background image view will not displaying

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

how to solve this ?

(如何解决呢?)

the layout in my fragment is like this

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

在此处输入图片说明

and here is the xml:

(这是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>
  ask by Alexa289 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just change your Recycler's TopToTop constrains to the id of the Image view and change it to TopToBottom.

(只需将Recycler的TopToTop约束更改为Image视图的ID,然后将其更改为TopToBottom。)

For doing so you also need to declare the imageview first so you'll be able to address its Id.

(为此,您还需要先声明imageview,以便能够解决其ID。)

Also give the banner width:match_parent

(还给横幅宽度: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"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...