android - 如何将 TextView 对齐到 ImageView 的右侧

标签 android xml

我是 android 开发的初学者,这是我的代码(它是相对布局)

<ImageView
    android:id="@+id/logo1"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:src="@drawable/telephone1"
    android:layout_marginTop="10dp"
    android:layout_below="@id/text4"/>

<TextView
    android:id="@+id/text5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="00966-13-8420444"
    android:fontFamily="sans-serif"
    android:textSize="20sp"
    android:layout_toRightOf="@id/logo1"
    />

我认为 android:layout_toRightOf="@id/logo1 就足够了 并且文本位于图像的右侧(正确对齐)但它出现在设备的顶部(图像位于底部但不在底部边缘),我应该添加哪一行代码?

对不起英语。 谢谢

最佳答案

如果我对你的问题的理解正确,你希望你的文字在图片之外,但与图片中心对齐,试试这个:

<ImageView
    android:id="@+id/logo1"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:src="@drawable/telephone1"
    android:layout_marginTop="10dp"
    android:layout_below="@id/text4"/>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_gravity="center_vertical">

    <TextView
        android:id="@+id/text5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="00966-13-8420444"
        android:fontFamily="sans-serif"
        android:textSize="20sp"
        android:layout_toRightOf="@id/logo1"/>
</LinearLayout>

关于android - 如何将 TextView 对齐到 ImageView 的右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38059647/

相关文章:

javascript - sencha 触摸 Controller 在导航 View 中不起作用

java - 对合并的 XML 文件进行编码

xml - XSD 可视化?

c# - 陷入 C# 中循环 XML 的思路中

java - 从服务访问静态变量

android - GCM token 什么时候到期,InstanceID 是什么?

Android 支持 CardView 的阴影问题

android - Key _id 需要 Parcelable 但值为 java.lang.Long。在 Activity 之间传递 Parceable 对象时

c# - 首先使用 Entity Framework 数据库从 SQL 查询 Xml

元素以任意顺序出现任意次数的 xml 架构构造