[英]Align element to the right in LinearLayout
我正在嘗試將快速badge
對齊到布局的右側,並且我需要title
盡可能寬。 這是我現在擁有的代碼。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:orientation="horizontal"
android:padding="@dimen/margin_large">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
tools:src="@drawable/ic_download" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical"
android:paddingStart="@dimen/margin_large"
android:paddingEnd="@dimen/margin_large">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
style="@style/AppTheme.Text.Light.SemiDarker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Example of title" />
<com.client.presentation.components.ChipView
android:id="@+id/badge"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/subtitle"
style="@style/AppTheme.Text.Body1.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Example of subtitle" />
</LinearLayout>
</LinearLayout>
線索是在 TextView 中將權重設置為 1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:minHeight="?attr/listPreferredItemHeight"
android:orientation="horizontal"
android:padding="@dimen/margin_large"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
tools:src="@drawable/ic_angry_android" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:paddingStart="32dp"
android:paddingEnd="32dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_weight="1"
style="@style/AppTheme.Text.Light.SemiDarker"
android:layout_width="0dp"
android:layout_height="wrap_content"
tools:text="Example of title" />
<....
</LinearLayout>
<TextView
android:id="@+id/subtitle"
style="@style/AppTheme.Text.Body1.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Example of subtitle" />
</LinearLayout>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.