0

Greatings everybody.

I was working on a simple custom ArrayAdapter when I bumped into an overlapping issue.

This is the xml of my layout:

<?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="wrap_content" >

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="@+id/label" />

    <EditText
        android:id="@+id/editText"
        android:hint="0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="10dp">
    </EditText>

</RelativeLayout>

The problem is that if the label is too long it overlaps the edittext element.

I have also tried using an horizontal layout with weights but the edittext gets out of the screen when the label is too long.

I have read like 6 posts about the relative layout overlapping but nothing seems to work.

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Kohakukun
  • 266
  • 4
  • 16
  • 2
    set Fixed width instead of wrap content – Pragnani Feb 11 '13 at 18:43
  • but how can have a value that changes with the screen size? – Kohakukun Feb 15 '13 at 23:40
  • why are you bothering about the screen size ? you are using 'dp(density independent pixels)' that name it self indicate that value will be changed on the screen size.. If you have any doubts regarding this http://stackoverflow.com/questions/2025282/difference-of-px-dp-dip-and-sp-in-android refer this – Pragnani Feb 16 '13 at 05:13

1 Answers1

1

Add android:layout_toRightOf="@id/label" to your edit text. That will make it always appear to the right of the label

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127