- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
要在约束布局中为一组 View 设置背景,想法是创建一个 View 项并将其约束到极端 View 的边界。但是,如果一组只依赖于右侧约束,则无法向左侧添加边距,因此可能设置背景的 View 组没有左侧填充,
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View"/>
<variable
name="audio"
type="example.model.observables.AttachmentObservableModel"/>
</data>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/selector_chat_row"
>
<include
android:id="@+id/message_preview_layout"
layout="@layout/reply_preview_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:minWidth="160dp"
android:layout_marginLeft="10dp"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Barrier
android:id="@+id/left_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="left"
app:constraint_referenced_ids="play_pause,message_preview_layout" />
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/chat_me_background"
app:layout_constraintBottom_toBottomOf="@+id/play_pause"
app:layout_constraintLeft_toLeftOf="@+id/left_barrier"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/play_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="@null"
android:enabled="@{!(audio.filePath == null || audio.filePath.isEmpty())}"
android:onClick="@{() -> audio.playing? audio.onPausePressed(): audio.onPlayPressed()}"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:src="@{audio.playing? @drawable/ic_pause_circle_filled: @drawable/ic_play_arrow}"
app:layout_constraintRight_toLeftOf="@+id/seekbar"
app:layout_constraintTop_toBottomOf="@+id/message_preview_layout" />
<android.support.v7.widget.AppCompatSeekBar
android:id="@+id/seekbar"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:enabled="@{!(audio.filePath == null || audio.filePath.isEmpty() || !audio.playing)}"
android:max="@{audio.max}"
android:onProgressChanged="@{audio::onProgressChanged}"
android:paddingStart="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:progress="@{audio.progress}"
android:progressTint="@color/selected"
android:secondaryProgressTint="@color/colorAccent"
android:thumbTint="@color/colorWhite"
app:layout_constraintBottom_toBottomOf="@+id/play_pause"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/play_pause" />
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="@color/color_offline"
android:visibility="@{(audio.filePath == null ||audio.filePath.isEmpty())? View.VISIBLE:View.GONE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/play_pause"
app:layout_constraintRight_toRightOf="@+id/seekbar"
app:layout_constraintTop_toTopOf="parent"
style="?android:attr/progressBarStyleSmall"/>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="15dp"
/>
</android.support.constraint.ConstraintLayout>
</layout>
这里我想在左侧添加一些填充,其中“view”是所有 View 的背景,但顶部 Constraint 布局具有不同的背景。目前它看起来像这样
最佳答案
找到解决方案。
在屏障左侧添加一个空 View ,宽度为所需的填充。
<View
android:id="@+id/left_view"
android:layout_width="15dp"
android:layout_height="1dp"
app:layout_constraintRight_toLeftOf="@+id/left_barrier"/>
现在将背景 View 的左侧设置为该 View 的左侧。即改变
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/chat_me_background"
app:layout_constraintBottom_toBottomOf="@+id/play_pause"
app:layout_constraintLeft_toLeftOf="@+id/left_barrier"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
到
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/chat_me_background"
app:layout_constraintBottom_toBottomOf="@+id/play_pause"
app:layout_constraintLeft_toLeftOf="@+id/left_view"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
关于java - 有什么方法可以在距离约束布局处设置障碍或在没有约束的情况下向 View 添加边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50794750/
我正在尝试从标准输入中获取一行。据我所知,我们永远不应该使用gets的手册页中所说的gets: Never use gets(). Because it is impossible to tell w
很多问题SO和文章/书籍,例如https://mirrors.edge.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.201
我认为 Coffeescript 是一门很棒的语言!我正在寻找一些将静态分析添加到 Coffeescript 的项目/问题/功能。然而,经过一番搜索后,我发现 Coffeescript faq和 th
以下查询返回过去 12 个月(针对特定客户)每周的订单总量: SELECT DATEPART(year, orderDate) AS [year], DATEPART(month, or
我觉得这可能是一个错误,任何人都可以重现或看到我做事方式的一些错误。 我正在尝试将 GKPolygonObstacle 添加到 iOS 或 macOS Playground 中的 GKMeshGrap
我的 SKSpriteKit 应用程序中有一个单独的“Floor”类。当我第一次创建这个类时,我使用 在整个框架周围设置了一个屏障 self.physicsBody = SKPhysicsBody(e
我有我正在尝试建模的半连续数据(许多精确的零和连续的正结果)。我从 Zuur 和 Ieno 的 R 中零膨胀模型初学者指南中学到了大量关于零质量的建模数据,它区分了零膨胀 Gamma 模型和他们所描述
以下代码实现了一些无锁(且无原子!)的线程间通信,这些通信需要使用存储和加载内存屏障,但是C++ 11 release-acquire语义不适当,也不保证正确性。实际上,该算法暴露了对发布获取语义的某
我指的是在 https://developer.android.com/training/constraint-layout/index.html#constrain-to-a-barrier 上使用
我正在一个非常好的 IBM x 服务器(4 个 8 核 CPU)上运行一些模拟应用程序的 x64 版本。操作系统是 Linux - redhat 5.6 x64 内核。因此,此应用恰好在需要超过 2
我是一名优秀的程序员,十分优秀!