删除锚点约束时,如何在约束布局中删除视图的边距
我的约束视图如下,其图像在
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/SellerProfileContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:visibility="@{sellerFullName != null ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toBottomOf="@id/Title"
app:layout_constraintStart_toStartOf="@id/Title"
app:layout_goneMarginTop="24dp">
<ImageView
android:id="@+id/SellerProfileImage"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:contentDescription="@{sellerProfileImageAccessibilityText}"
android:scaleType="centerCrop"
android:visibility="@{sellerProfileImage != null ? View.VISIBLE : View.GONE}"
android:src="@{sellerProfileImage}" />
<TextView
android:id="@+id/SellerProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:contentDescription="@{sellerFullName}"
android:text="@{sellerFullName.text}"
android:visibility="@{sellerFullName != null ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toTopOf="@id/SellerProfileImage"
app:layout_constraintBottom_toBottomOf="@id/SellerProfileImage"
app:layout_constraintStart_toEndOf="@id/SellerProfileImage"
app:layout_constraintEnd_toEndOf="parent"
tools:text="Seller Profile Name"
/>
<TextView
android:id="@+id/SellerRatings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{sellerFeedbackPercent}"
android:contentDescription="@{sellerFeedbackPercent}"
android:textColor="@color/style_guide_neutral6"
android:visibility="@{sellerFeedbackPercent != null ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="@id/SellerProfile"
app:layout_constraintTop_toBottomOf="@id/SellerProfile"
tools:text = "100% positive rating"/>
</androidx.constraintlayout.widget.ConstraintLayout>
我尝试实现布局,如下所示:
- 如果
sellerProfileimage
不是null,则sellererProfileimage
和sellerProfile
在它们之间的保证金应为16DP。 - 如果
sellerProfileimage
为null,则sellerProfile
在父(约束布局)和本身之间应为零。
我尝试了sellerProfile
的以下方法
- ,我做了以下
android:layout_marginstart =“ @{uxcontent.sellerprofileimage!= null? @dimen/margin_16dp: @dimen/margin_16dp: @dimen/margin_0dp} >
Margin_16DP
和Margin_0dp
分别等于16DP和0DP。
但是,当我编译代码时,我会收到以下错误,该错误
Cannot find a setter for <android.widget.TextView android:layout_marginStart> that accepts parameter type 'float'
If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.
如何根据是否存在卖方配置文件有条件地调整布局的开始边距?
I have a constraint view as follows, the image of which is given below
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/SellerProfileContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:visibility="@{sellerFullName != null ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toBottomOf="@id/Title"
app:layout_constraintStart_toStartOf="@id/Title"
app:layout_goneMarginTop="24dp">
<ImageView
android:id="@+id/SellerProfileImage"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:contentDescription="@{sellerProfileImageAccessibilityText}"
android:scaleType="centerCrop"
android:visibility="@{sellerProfileImage != null ? View.VISIBLE : View.GONE}"
android:src="@{sellerProfileImage}" />
<TextView
android:id="@+id/SellerProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:contentDescription="@{sellerFullName}"
android:text="@{sellerFullName.text}"
android:visibility="@{sellerFullName != null ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toTopOf="@id/SellerProfileImage"
app:layout_constraintBottom_toBottomOf="@id/SellerProfileImage"
app:layout_constraintStart_toEndOf="@id/SellerProfileImage"
app:layout_constraintEnd_toEndOf="parent"
tools:text="Seller Profile Name"
/>
<TextView
android:id="@+id/SellerRatings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{sellerFeedbackPercent}"
android:contentDescription="@{sellerFeedbackPercent}"
android:textColor="@color/style_guide_neutral6"
android:visibility="@{sellerFeedbackPercent != null ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="@id/SellerProfile"
app:layout_constraintTop_toBottomOf="@id/SellerProfile"
tools:text = "100% positive rating"/>
</androidx.constraintlayout.widget.ConstraintLayout>
I am trying implement the layout as follows:
- If the
sellerProfileImage
is not null, thensellerProfileImage
andsellerProfile
should have a margin of 16dp between them. - If the
sellerProfileImage
is null, thensellerProfile
should have zero margin between the parent (constraint layout) and itself.
I tried the following approach
- For
sellerProfile
, I did the followingandroid:layout_marginStart="@{uxContent.sellerProfileImage != null ? @dimen/margin_16dp : @dimen/margin_0dp}"
where themargin_16dp
andmargin_0dp
equals 16dp and 0dp respectively.
But when I compiled the code, I got the following error
Cannot find a setter for <android.widget.TextView android:layout_marginStart> that accepts parameter type 'float'
If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.
How can I conditionally adjust the start margin of the layout depending on whether the seller profile is present or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要调整布局中的边距,以利用“消失”边距。看
“ noreferrer”>“ noreferrer”> Margins> Margins> Margins> Margins当连接到gothing dogget 。
这是您的布局的简化版本:
我对两个小部件的边缘进行了调整。关键更改是设置
app:layout_gonemarginstart =“ 0dp”
在 textView 上。当图像为gone
时,这将设置为0DP
。和
16DP
当图像为可见
时。您应该能够在不使用数据绑定的情况下完成布局的这一方面。
You will want to adjust the margins in your layout to make use of "gone" margins. See
Margins when connected to a GONE widget.
Here is a simplified version of your layout as an example:
I made adjustments to the margins of the two widgets. The key change is setting
app:layout_goneMarginStart="0dp"
on the TextView. This will set the start margin to0dp
when the image isgone
.and to
16dp
when the image isvisible
.You should be able to accomplish this aspect of your layout without the use of data binding.