gpt4 book ai didi

java - 有什么方法可以在距离约束布局处设置障碍或在没有约束的情况下向 View 添加边距?

转载 作者:太空狗 更新时间:2023-10-29 13:48:15 25 4
gpt4 key购买 nike

要在约束布局中为一组 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 布局具有不同的背景。目前它看起来像这样 enter image description here

最佳答案

找到解决方案。

在屏障左侧添加一个空 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/

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