简体   繁体   English

如何将textview对齐到imageview的右边

[英]how to align a textview to the right of imageview

I'm a beginner in android development and this is my code (it's relative layout) 我是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"
    />

I thought android:layout_toRightOf="@id/logo1 is enough and the text was on the right of the image (aligned correctly) but it appears on the top of device (the place of image on the bottom but not on bottom edge), what line of code I should add? 我认为android:layout_toRightOf =“ @ id / logo1就足够了,文字在图片的右边(正确对齐),但是它出现在设备的顶部(图片的位置在底部,但不在底部边缘),我应该添加哪一行代码?

sorry for English. 对不起,英语。 thank you 谢谢

If I understood your question correctly, you want your text outside the picture, but aligned to its center, try this: 如果我正确理解了您的问题,则希望文本在图片之外,但要与图片中心对齐,请尝试以下操作:

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

If I have understood your questions clearly, You want to display image and textview in a single row. 如果我清楚地理解了您的问题,则希望在一行中显示图像和文本视图。 Also, Your textview is right side of imageView. 另外,您的textview在imageView的右侧。 If it is so. 如果是这样。 Please copy/paste below. 请在下面复制/粘贴。 It should work 它应该工作

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/logo1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:src="@mipmap/ic_launcher"/>

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

You can make a Layout Structure like this and then Move around the LinearLayout wherever you like using android:gravity 您可以像这样制作一个布局结构,然后使用android:gravityLinearLayout位置移动LinearLayout

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="Horizontal">

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

<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"
    />

</LinearLayout>

try this 尝试这个

 <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"
        android:layout_alignParentLeft="true"/>

    <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_alignParentRight="true"
        android:layout_toRightOf="@id/logo1"

/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM