我有一个相对的布局如下:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.38"
android:background="@drawable/layout"
android:orientation="vertical" >
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:layout_marginLeft="80dp"
android:textColor="@color/text1color"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text2"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/text1"
android:layout_below="@+id/text1"
android:background="@drawable/text2_background"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:textColor="@color/text2color"
android:textSize="13sp" />
<com.widgets.CustomImageView
android:id="@+id/myImage"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="0dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/text2"
android:src="@drawable/logo" />
</RelativeLayout>ImageView @+id/myImage需要与@+id/text2 TextView的中心对齐!目前,它与@+id/text2 的顶部保持一致,与布局的parentBottom保持一致。我不想要这个黑客。
有没有办法使ImageView与TextView的中心保持一致?
发布于 2014-03-23 17:25:53
这是一个完美的情况下的复合拉伸(这是一个最佳做法,使您的设计扁平)。
ImageView进入TextView text2,在其底部:
只需将此添加到您的text2定义:
android:drawableBottom="@drawable/logo"你也可以加点垫子。
android:drawablePadding="4dp"图像与其容器水平对齐。
如果文本垂直增长,图像将被下拉(随着TextView的增长)。
要使图像保持对齐和垂直居中,只需使用drawableTop更改drawableLeft,您就完成了:
android:drawableLeft="@drawable/logo"https://stackoverflow.com/questions/22594144
复制相似问题