1

I have been having trouble getting this LinearLayout to move to the vertical center of the RelativeLayout which is it's parent. I have tried many methods and maybe I am using the wrong one but I am not sure. Can someone just check it over to see what I need to add. Thanks. There is some TextViews to the right of the LinearLayout but I didn't include them as you don't require them but just remember the layout needs to be in the vertical center of the RelativeLayout and not in the complete center.

<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>
4

2 回答 2

3

如果您需要将 a 中的元素垂直居中RelativeLayout,在您的特定情况下为LinearLayout, 然后将android:layout_centerVertical="true"属性添加到 LinearLayout。

于 2013-07-21T11:57:21.217 回答
1

首先在相对内部使用线性不是一个好主意,我更喜欢你改变它,但如果你想保持不变,不能在 middel 中移动线性布局,你必须移动你的图像

现在有很多方法比如

android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_centerVertical="true"

另外,您可以手动提供边距输入

android:layout_marginTop="162dp" android:layout_marginleft="80dp"..

首先尝试这些,但仍然强烈建议使用线性或相对,你总是可以在设计视图中拖动你的 UI。

于 2013-07-21T12:03:36.023 回答