Issue in android layout?

How to avoid this (highlighted in red):

14519bba79fdc37b24c2739717b5f046.png


File row.xml
<?xml version="1.0" encoding="utf-8"?>
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="parent" android:layout_height="parent" android:orientation="vertical">

 <imageview android:id="@+id/istar" android:layout_width="30dp" android:layout_height="30dp" android:paddingleft="10dp" android:layout_centervertical="true" android:scaletype="fitCenter" android:src="@drawable/star">

 <textview android:id="@+id/imain" android:layout_width="wrap content" android:layout_height="wrap content" android:padding="20dp" android:layout_torightof="@id/istar" android:text="TextView" android:layout_gravity="center_vertical|left">
</textview>

 <textview android:id="@+id/iname" android:layout_width="wrap content" android:layout_height="wrap content" android:padding="20dp" android:layout_torightof="@id/imain" android:text="TextView" android:layout_gravity="center_vertical|left" android:textsize="20sp">
</textview>

 <textview android:id="@+id/icurrency" android:layout_width="wrap content" android:layout_height="wrap content" android:paddingleft="5dp" android:paddingtop="20dp" android:paddingbottom="20dp" android:paddingright="20dp" android:text="TextView" android:layout_alignparentright="true" android:textsize="20sp">
</textview>

 <textview android:id="@+id/ibalance" android:layout_width="wrap content" android:layout_height="wrap content" android:paddingleft="20dp" android:paddingtop="20dp" android:paddingbottom="20dp" android:paddingright="5dp" android:text="TextView" android:layout_toleftof="@id/icurrency" android:textsize="20sp">
</textview>

</imageview></relativelayout>



Thanks in advance!
October 3rd 19 at 02:40
6 answers
October 3rd 19 at 02:42
Solution
Use LinearLayout, the elements width fill_parent. Adjust the width of the weight (I was not wrong, weight), maxwidth, minwidth. Should work. Or you can use a TableLayout.
You can also try to place a TextView at the back and set indents using the parent. Also should work. - brock_Labadie commented on October 3rd 19 at 02:45
October 3rd 19 at 02:44
Readonly user yasevich suggested:
In main you need to register
android:layout_toLeftOf="@id/icurrency". 
Well and accordingly to order the elements in the XML.
October 3rd 19 at 02:46
Look at this code. There you described the problem is solved.
October 3rd 19 at 02:48
<?xml version="1.0" encoding="utf-8"?>
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="parent" android:layout_height="wrap content">

 <imageview android:id="@+id/image" android:layout_width="wrap content" android:layout_height="wrap content" android:layout_alignparentleft="true">

 <textview android:id="@+id/usd" android:layout_width="wrap content" android:layout_height="wrap content" android:layout_alignparentright="true">

 <textview android:id="@+id/your_text" android:layout_width="parent" android:layout_height="wrap content" android:layout_torightof="@+id/image" android:layout_toleftof="@+id/usd">

</textview></textview></imageview></relativelayout>


Height/width and vertical alignment — at your discretion.
October 3rd 19 at 02:50
I nikgoda didn't answer Android questions on the layout, but after watching this, I'm terrified.
1. avoid RelativeLayout!
2. redo on
<linearlayout width="parent" height="wrap content" orientation="horizontal" weight_sum="1">
 <textview layoutweight="1" width="0dp" height="wrap content" drawable_left="@drawable/some_star_selector">
 <textview width="wrap content">
 <textview width="wrap content">
</textview></textview></textview></linearlayout>
And you can see where Google advises to avoid RelativeLayout? Or at least what it wrong? - brock_Labadie commented on October 3rd 19 at 02:53
October 3rd 19 at 02:52
In General, several times tried to describe it, but accidentally closed the page so I will say briefly, using ConstraintLayout can be implemented avoiding attachments, example:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:background="@color/light_gray" android:layout_width="parent" android:layout_height="wrap content">

 <imageview android:id="@+id/imageView5" android:layout_width="wrap content" android:layout_height="wrap content" android:layout_marginbottom="16dp" android:layout_marginend="16dp" android:layout_marginstart="16dp" android:layout_margintop="16dp" app:layout_constraintbottom_tobottomof="parent" app:layout_constraintend_tostartof="@+id/textView11" app:layout_constrainthorizontal_bias="0.5" app:layout_constraintstart_tostartof="parent" app:layout_constrainttop_totopof="parent" app:layout_constraintvertical_bias="0.0" app:srccompat="@drawable/googleg_standard_color_18">

 <textview android:id="@+id/textView11" android:layout_width="0dp" android:layout_height="wrap content" android:layout_marginend="8dp" android:text="TextViewTextViewTextViewTextViewtextviewtextviewtextviewtextviewtextviewtextview" app:layout_constraintbottom_tobottomof="@+id/imageView5" app:layout_constraintend_tostartof="@+id/textView12" app:layout_constrainthorizontal_bias="0.5" app:layout_constraintstart_toendof="@+id/imageView5" app:layout_constrainttop_totopof="@+id/imageView5" app:layout_constraintvertical_bias="0.0">

 <textview android:id="@+id/textView12" android:layout_width="wrap content" android:layout_height="wrap content" android:layout_marginend="8dp" android:text="TextView" app:layout_constraintbottom_tobottomof="@+id/textView11" app:layout_constraintend_tostartof="@+id/textView13" app:layout_constrainthorizontal_bias="0.5" app:layout_constraintstart_toendof="@+id/textView11" app:layout_constrainttop_totopof="@+id/textView11" app:layout_constraintvertical_bias="0.0">

 <textview android:id="@+id/textView13" android:layout_width="wrap content" android:layout_height="wrap content" android:layout_marginend="8dp" android:text="TextView" app:layout_constraintbottom_tobottomof="@+id/textView12" app:layout_constraintend_toendof="parent" app:layout_constrainthorizontal_bias="0.5" app:layout_constraintstart_toendof="@+id/textView12" app:layout_constrainttop_totopof="@+id/textView11">
</textview></textview></textview></imageview></android.support.constraint.constraintlayout>


5aafe3d2b50e8628578894.jpeg5aafe3d8975bf292610635.jpeg

Find more questions by tags Android