我一直很难让这个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。

关于android - 将ImageView移至RelativeLayout的中间-Android,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17772016/

10-12 02:29