android - 如何约束保证金结束?
问题描述
我想添加arrow icon
一个end
:LinearLayout
实现这一目标的最佳方法是什么?
LinearLayout
我成功地将and包裹ImageView
起来ConstraintLayout
,但感觉有比使用更优雅的方式app:layout_constraintHorizontal_bias="1"
。
在第一次尝试ImageView
时,是LinerLayout
(没有ConstraintLayout
)的一部分,有没有办法从这里获得所需的布局?
当前.xml
:
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 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="match_parent"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/profile_constraint_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_16sdp">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/profile_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imageView"
android:layout_marginStart="@dimen/_4sdp"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/ic_account_circle_black_48dp"
android:contentDescription="@string/nav_bottom_sheet_profile_description" />
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginStart="@dimen/_4sdp">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/jesta_profile_full_name_default"/>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/jesta_profile_phone_number_default"/>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/jesta_profile_edit_profile_icon_description"
android:src="@drawable/ic_keyboard_arrow_right_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/profile_layout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="1"/>
</androidx.constraintlayout.widget.ConstraintLayout>
...
</androidx.appcompat.widget.LinearLayoutCompat>
解决方案
仅将箭头图标限制为top
,bottom
和end
,它将自动附加到布局的最后
所以而不是这个:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/jesta_profile_edit_profile_icon_description"
android:src="@drawable/ic_keyboard_arrow_right_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/profile_layout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="1"/>
拥有这个:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/jesta_profile_edit_profile_icon_description"
android:src="@drawable/ic_keyboard_arrow_right_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
推荐阅读
- javascript - 从 Swift 调用 Javascript 函数返回未定义
- groovy - 闭包属性后执行
- java - 我有一个包含字符串的列表。如何在每一个上使用 .split()(使用 forEach)?
- javascript - React 不执行组件中的功能
- tcp - 具有自定义 TCP 读取缓冲区的 HTTP2 客户端
- swift - tintedImageProvider 在图形复杂化中不提供色调颜色
- javascript - React:使用 react-navigation 和 react-router 时如何更改页面?
- php - 解析错误:语法错误,第 12 行 C:\xampp\htdocs\Chat\Chat\includes\signup.inc.php 中的意外“退出”(T_EXIT)
- android - 如何检查活动是否与元数据标签相关联?
- python - 使用 Python 制作解析器时的移位/减少冲突