When you work with RelativeLayout
you should take into account the relative position of the elements around you, for example: the left of (android:layout_toLeftOf
), below (android:layout_below
), etc. When you want to do the distribution of the elements considering a weight (android:layout_weight
) utilize LinearLayout
, otherwise you won’t have the expected result.
In the layout that you did, you used at the same time in TextView
the properties: android:layout_alignParentLeft="true"
and android:layout_alignParentRight="true"
, that is, you determined that your TextView
will be aligned left and right, occupying the entire width of the parent element (RelativeLayout
).
So that your TextView
not be superimposed by other elements, remove from it the line android:layout_alignParentRight="true"
, can also remove the android:layout_weight
, they will not make any difference (in this case), your XML should look like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvBoleiro"
android:layout_width="wrap_content"
android:layout_height="40sp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:layout_toLeftOf="@+id/ivGols"
android:ellipsize="end"
android:focusable="false"
android:focusableInTouchMode="false"
android:maxLines="1"
android:textSize="25sp" />
<ImageView
android:id="@id/ivGols"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/btPagamento"
android:background="@null"
android:contentDescription="@string/app_name"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="@drawable/ic_gol" />
<Button
android:id="@id/btPagamento"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/tvBoleiro"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:focusable="false"
android:focusableInTouchMode="false" />
</RelativeLayout>
If you choose to use LinearLayout
, an alternative would be:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvBoleiro"
android:layout_width="0dp"
android:layout_height="40sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:layout_weight=".65"
android:ellipsize="end"
android:focusable="false"
android:focusableInTouchMode="false"
android:maxLines="1"
android:textSize="25sp" />
<ImageView
android:id="@+id/ivGols"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".15"
android:background="@null"
android:contentDescription="@string/app_name"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="@drawable/ic_gol" />
<Button
android:id="@+id/btPagamento"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:focusable="false"
android:focusableInTouchMode="false" />
</LinearLayout>
Note: used android:layout_width="0dp"
so that the elements are distributed correctly according to their weights and android:maxLines="1"
to appear the ...
when and text is greater than the limit.
References
Linear Layout
Relative Layout
Add ellipsis in Textview with one or multiple lines
A doubt, you posted the entire XML?
– Guilherme Nascimento
Yes @Guilhermenascimento
– tbalbinos
They are two XML’s one with only Listview and another that is the one I posted that makes the listview line
– tbalbinos
I can’t tell you this, but I wanted to limit the textview size so it doesn’t look like this, I was able to edit the post with full xml.
– tbalbinos
Good afternoon, did any of the answers solve your problem? If yes please mark it as "Correct". If you do not say what is missing. Thank you.
– Guilherme Nascimento