[英]How to Constraint to Margin end?
I want to add an arrow icon
to end
of LinearLayout
: 我想在LinearLayout
end
添加一个arrow icon
:
What is the best way to accomplish this? 做到这一点的最佳方法是什么?
I succeed by wrapping the LinearLayout
and ImageView
with ConstraintLayout
, but it feels that there is a more elegant way than using app:layout_constraintHorizontal_bias="1"
. 我通过使用ConstraintLayout
包装LinearLayout
和ImageView
成功完成,但是感觉比使用app:layout_constraintHorizontal_bias="1"
更加优雅。
On first attempt the ImageView
was part of the LinerLayout
(without the ConstraintLayout
), is there is a way to get the desired layout from here? 第一次尝试时, ImageView
是LinerLayout
一部分(没有ConstraintLayout
),有没有办法从此处获取所需的布局?
Current .xml
: 当前.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>
Constrain your arrow icon only for the top
, bottom
and end
, it will automatically affix itself in the very end of your layout 仅将箭头图标约束在top
, bottom
和end
,它会自动在布局的最后粘贴自己
so instead of this: 所以代替这个:
<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"/>
have this: 有这个:
<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"
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.