[英]Android - How to fix position of image
我有一個LinearLayout
,其中有許多文本字段,並且在LinearLayout
的右側有一個ImageView
。 但是,圖像的位置永遠不會固定,並且會根據TextView
字段的內容而移動。 我該如何解決這個問題? 我試過操縱android:layout_gravity
但這沒有給我解決方案。 無論TextView
的內容如何,我都希望自己的圖像停靠在右側。 這是我的布局文件。 任何指針或解決方案將不勝感激。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="144dp"
android:orientation="vertical"
android:layout_gravity="left"
>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/name_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/date_of_birth_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/date_of_birth" />
<TextView
android:id="@+id/date_of_birth"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/place_of_birth_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/place_of_birth" />
<TextView
android:id="@+id/place_of_birth"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/height_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/height" />
<TextView
android:id="@+id/height"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/blood_type_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/blood_type" />
<TextView
android:id="@+id/blood_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/member_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
/>
</LinearLayout>
在最外面的布局中使用RelativeLayout。 您可以將圖像設置為在右側垂直顯示。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="144dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/name_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/date_of_birth_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/date_of_birth" />
<TextView
android:id="@+id/date_of_birth"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/place_of_birth_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/place_of_birth" />
<TextView
android:id="@+id/place_of_birth"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/height_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/height" />
<TextView
android:id="@+id/height"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/blood_type_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/blood_type" />
<TextView
android:id="@+id/blood_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/member_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.