How can I prevent my TextView from overlapping?

蓝咒 提交于 2019-12-12 15:47:53

问题


How can I prevent this overlapping from occurring without reducing the font size? Here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">   
    <TextView
        android:id="@+id/nameText"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Symbol"
        android:textStyle="bold"
        android:textSize="24sp"
        android:layout_width="100dp"
        android:textColor="#4871A8"
        android:paddingTop="2dip"
        android:paddingLeft="5dip"
        android:paddingBottom="1dip"/>
    <TextView
        android:id="@+id/changeText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:gravity="right"     
        android:textSize="18sp"
        android:paddingTop="9dip"
        android:paddingRight="5dip"
        android:paddingBottom="1dip" android:text="13.07(+43.08%)" android:paddingLeft="5dip"/>  
    <ImageView android:layout_toLeftOf="@+id/changeText" android:layout_width="wrap_content" android:layout_height="fill_parent" android:id="@+id/verticalDivider" android:background="@drawable/stocks_selected_gradient"></ImageView><TextView
        android:id="@+id/priceText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/changeText"
        android:gravity="right"     
        android:textStyle="bold"
        android:textSize="24sp"
        android:textColor="#4871A8"
        android:paddingTop="2dip"
        android:paddingBottom="1dip"
        android:paddingRight="25dip" android:text="15000"/>  

</RelativeLayout>

回答1:


In your second TextView, change android:layout_alignParentRight="true" to

android:layout_toRightOf="@+id/nameText"



回答2:


Encapsulate the TextViews in a LinearLayout (orientation = horizontal). For the individual TVs specify android:layout_weight (remember weights work differently when using android:layout_width=fill_parent/wrap_content)



来源:https://stackoverflow.com/questions/3819760/how-can-i-prevent-my-textview-from-overlapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!