[英]Getting ImageView to middle of RelativeLayout - Android
我一直無法讓這個LinearLayout移動到RelativeLayout的垂直中心,這是它的父級。 我嘗試了很多方法,也許我使用了錯誤的方法,但我不確定。 有人可以檢查一下,看看我需要添加什么。 謝謝。 LinearLayout右側有一些TextView,但我沒有包含它們,因為你不需要它們,但只記得布局需要在RelativeLayout的垂直中心,而不是在完整的中心。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_card"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:gravity="center"
android:background="@drawable/image_bg"
android:layout_marginRight="5dip">
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/thumb"/>
</LinearLayout>
如果你需要在RelativeLayout
垂直居中一個元素,在你的特定情況下是LinearLayout
,那么將android:layout_centerVertical="true"
屬性添加到LinearLayout。
首先使用線性內部相對不是一個好主意,我更喜歡你改變它但仍然如果你想保持它相同,不能移動middel中的線性布局,你必須移動你的圖像
現在有很多方法如
android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_centerVertical="true"
另外,您可以手動提供保證金 - 輸入
android:layout_marginTop="162dp" android:layout_marginleft="80dp"
..
首先嘗試這些,但仍然強烈建議使用線性或相對,你總是可以在設計視圖中拖動你的UI。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.