- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 ViewHolder
,标题位于顶部,该标题在特定情况下变得可见。在大多数其他情况下, header 设置为 GONE
。问题是,当 header 设置为 GONE 时,它的高度仍会计算,而其他 View 的传播
不同(之间有更多空间)。
蓝图说明:
顶部
、左侧
和右侧
。打包链
中,限制在顶部
的标题,ImageView
在右侧
和 left
和 bottom
的父级。下面是布局检查器的屏幕截图,其中突出显示的标题 View 设置为 GONE
:
根据文档,当设置为 GONE
时,header view 应该缩小到指向仍然应用其他 View 的约束,但 header 不应该占用布局空间和影响高度ConstraintLayout
被设置为 wrap_content
。
在此检查器屏幕截图中,不清楚实际发生了什么。标题不可见,底部 View 显然受限于父级顶部,但标题在检查器中仍显示为具有指定高度的全宽。
我不确定这是一个错误还是我应该强制 ConstraintLayout
重新测量自己。
XML 更新:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/list_item_step_conversion_tv_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/gray_very_light"
android:padding="@dimen/activity_vertical_margin"
android:text="@string/favorites"
android:textColor="@android:color/black"
android:textSize="@dimen/default_text_size"
android:textStyle="bold"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/list_item_step_conversion_tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/gray_dark"
android:textSize="@dimen/medium_text_size"
app:layout_constraintBottom_toTopOf="@+id/list_item_step_conversion_tv_description"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/list_item_step_conversion_iv_favorite"
app:layout_constraintTop_toBottomOf="@+id/list_item_step_conversion_tv_header"
app:layout_constraintVertical_chainStyle="packed"
tools:text="Bicycling - light (10-11.9 mph)"/>
<TextView
android:id="@+id/list_item_step_conversion_tv_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="16dp"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/black"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/list_item_step_conversion_tv_title"
app:layout_constraintRight_toLeftOf="@+id/list_item_step_conversion_iv_favorite"
app:layout_constraintTop_toBottomOf="@+id/list_item_step_conversion_tv_title"
tools:text="182 steps/minute"/>
<ImageView
android:id="@+id/list_item_step_conversion_iv_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginRight="24dp"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/list_item_step_conversion_tv_header"
app:srcCompat="@drawable/ic_not_liked"/>
</android.support.constraint.ConstraintLayout>
更新 2
经过进一步观察,只有在 RecyclerView.Adapter
中调用 notifyDataSetChanged
后才会出现此问题。这是单击其中一项的 favorite
图标之前和之后布局状态的屏幕截图。
截图说明:
header
View 的ViewHolder
位于位置:2
。上面的项目显示正确。 favorite
图标(值为 242 的项目)后,position: 1
上的 ViewHolder
是带有可见 header 的那个
View ,而 position: 2
上的 ViewHolder
将 header
View 设置为 GONE
。我期望 ViewHolder
高度降低并与 position: 0
上的 ViewHolder
具有相同的高度。请记住,此 ViewHolder
在之前的状态下将 header
设置为 VISIBLE
,它可能具有回收功能,不确定。
最佳答案
我已经通过在我的适配器的 #getView
的末尾调用 view.requestLayout()
* 解决了这个问题,在通常调用 绑定(bind)之后。 executePendingBindings()
.
*我现在使用的是老式的 Adapter
,因此您应该搜索 RecyclerView.Adapter
的等效项,可能是 #onBindViewHolder( )
关于android - ConstraintLayout GONE View 占用空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43680557/
我最近从 mysql_ 切换到 PDO,这真的很痛苦。一切看起来都那么复杂。 过去我开发了一个系统,用户可以导入包含记录的 csv。然后通过 while 循环将这些行导入数据库。它在 mysql_qu
android 布局使用 layout_weight。我的目标是所有组件的 1/3,但有时页脚实际上设置为消失,然后可见。从 gone 设置为 visible 时,权重计算如何工作?我没有看到具有 1
我想要一个小的“标题”,当我单击它时,其余内容会使用向上滑动动画显示。 我已经尝试了一些动画,但我唯一想做的就是在其父级中为内容设置动画。我想要的是,当我单击标题时,整个标题和内容(具有可见性 GON
我使用 Firebase 和 RadioButton 获得 2 种类型的数据,我对显示的数据进行排序。一切似乎都正常,但是当隐藏其中一种数据类型时仍然有一个空白空间。告诉我如何正确隐藏/显示数据。 T
我的 Jersey API 如下: @DELETE @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON
在 VBA Excel 中,如果我在关闭并再次打开文件后使用 UserInterFaceOnly:=True 选项保护工作表,则 UserInterFaceOnly 模式不会激活,只有密码保护。 代码
如果设备设置为英国英语,我不想显示布局。最好的方法是什么?每次获取设备语言? 最佳答案 往这边走,GB代表大不列颠(英国) String locale = context.getResources()
我的布局中有来自设计支持库的 FAB: //....
当我尝试在 Eclipse 中使用图形布局界面(而不是 xml)进行布局时,我遇到了这个问题: 假设我的主要布局只是屏幕底部的一个简单按钮,单击该按钮时,会打开一个覆盖大部分屏幕的文本框。 注意:我这
在我的应用程序中,我有 RelativeLayout 和任何小部件,进入布局,我想通过 xml 动画将其向上移动。 RelativeLayout 可见性为 GONE 并且必须再次将可见性设置为 GON
我的 XMl 中有这段代码。由于某种原因, View 仍然可见。我还有其他 block 可以使其在特定时间点可见,但我已经将它们注释掉了。这是保留此 View 的最后一段代码,出于某种原因我仍然可以看
我有一个包含一个 TextView 和两个图像的相对布局(宽度固定宽度,高度 = 48dip)。当我为一张图片设置 visibility view.gone 时,它不会释放空间 最佳答案
所以我有一个应用程序,当用户点击 button 时,将为带按钮的 layout 执行 animation(例如 滑动菜单),然后如果他点击另一个按钮,它必须使第一个布局不可见或消失,然后是新布局。 但
我想问一下,如何为 Admob 实现 AdListner。我希望广告在点击后消失。我试过了,但没有用。 final AdView ad1 = (AdView) findViewById(R.id.ad
我想将一个 View 设置为 GONE,然后让其他 View 占用剩余空间。 现在,如果我将它设置为 GONE,它会在布局中原来的位置留下一个空间,该 View 是一个具有固定高度的 viewpage
pypi.python.org has been migrated to pypi.org之后,我在尝试像往常一样使用命令将包上传到 PyPI 时遇到错误: python2.7 setup.py sd
我有一个自定义搜索面板,它是主布局的一部分。大多数时候面板是隐藏的。我想在面板上添加出现/消失的动画。这是简化的布局摘录: > > 尝
我遇到了一个问题,即可见性状态为 GONE 的 View (不希望地)占用了屏幕空间。这个问题总是发生在 API 级别 <= 7 的设备上,但最近才发生在 8+ 设备上(在我使用 AsyncTasks
所以我的应用程序中有一个 GLSurfaceView,由 GLSurfaceView.Renderer 渲染并使用 JPCt 作为库。 表面处于不可见的 RelativeLayout 中(可见性:消失
我有一个巨大的 XML 布局,其中有许多 Relative/Linear 布局,我现在正在做的是使用 setVisibility (View. GONE) 并在需要时更改其可见性。 我的问题是:这种方
我是一名优秀的程序员,十分优秀!