首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将ImageView对齐到TextView在RelativeLayout中的中心

将ImageView对齐到TextView在RelativeLayout中的中心
EN

Stack Overflow用户
提问于 2014-03-23 17:12:50
回答 1查看 1.6K关注 0票数 0

我有一个相对的布局如下:

代码语言:javascript
复制
<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保持一致。我不想要这个黑客。

有没有办法使ImageViewTextView中心保持一致?

EN

回答 1

Stack Overflow用户

发布于 2014-03-23 17:25:53

这是一个完美的情况下的复合拉伸(这是一个最佳做法,使您的设计扁平)。

ImageView进入TextView text2,在其底部:

只需将此添加到您的text2定义:

代码语言:javascript
复制
android:drawableBottom="@drawable/logo"

你也可以加点垫子。

代码语言:javascript
复制
android:drawablePadding="4dp"

图像与其容器水平对齐。

如果文本垂直增长,图像将被下拉(随着TextView的增长)。

要使图像保持对齐和垂直居中,只需使用drawableTop更改drawableLeft,您就完成了:

代码语言:javascript
复制
android:drawableLeft="@drawable/logo"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22594144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档