gpt4 book ai didi

android - 滚动时 Recyclerview 高度逐渐改变

转载 作者:行者123 更新时间:2023-11-29 18:52:48 26 4
gpt4 key购买 nike

我有一个recyclerview,我在其中添加了一个elevation。似乎高度会随着项目在屏幕上的垂直位置而变高,阴影会随着项目向下滚动而增加。我试过添加背景颜色,但没有用。我找到了另一篇帖子,其中包含显示问题的视频。 https://youtu.be/nROYq8rpUMs

这是我添加高度的相对布局。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EDEDED"
android:focusable="?attr/selectableItemBackground"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:id="@+id/newsRowRelativeLayout"
android:elevation="4dp">

<ImageView
android:id="@+id/newsImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxHeight="300dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="15dp"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:background="@color/mainTextBGColor" />

<TextView
android:id="@+id/newsTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:layout_below="@id/newsType"
android:textStyle="bold"
android:textColor="@color/news_title"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:textSize="@dimen/news_title_main" />

<TextView
android:id="@+id/newsType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:layout_below="@id/newsImage"
android:textStyle="bold"
android:textAllCaps="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:textColor="@color/mainBGColor"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:textSize="@dimen/news_tag_detailed" />

<TextView
android:id="@+id/newsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/newsTitle"
android:background="@android:color/transparent"
android:ellipsize="end"
android:maxLines="3"
android:textColor="@color/news_text"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:textSize="@dimen/news_text_main"/>

</RelativeLayout>

最佳答案

这没什么问题。 Elevation 效果使用所谓的Key-LightAmbient-Light。一个位于屏幕正上方(环境光),另一个(主光)在屏幕上方呈 45° 角。这就是为什么在滚动时阴影会移动的原因。

长话短说阴影不是静态的,而是动态计算的。另见下图解释概念:

material design shadows concept

关于android - 滚动时 Recyclerview 高度逐渐改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50560689/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com