android - Prevent view overlapping in RelativeLayout -
i'm trying accomplish simple layout task, i'm stuck view overlapping in relativelayout
.
screenshot:
the title textview
should centered (both vertically , horizontally). problem when title bit longer , covers button
.
the desired behaviour title textview
aligns left button, or trims (e.g. singleline
).
here xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <relativelayout android:layout_width="match_parent" android:layout_height="50dp" android:background="#ffffff"> <linearlayout android:id="@+id/backbutton" android:layout_width="100dp" android:layout_height="match_parent" android:background="#cccccc"> <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center" android:text=" < back" android:textsize="20sp" /> </linearlayout> <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_centerhorizontal="true" android:gravity="start|center_vertical" android:text="centered title" android:textsize="22sp" /> </relativelayout> <relativelayout android:layout_width="match_parent" android:layout_height="50dp" android:layout_margintop="30dp" android:background="#ffffff"> <linearlayout android:id="@+id/backbutton2" android:layout_width="100dp" android:layout_height="match_parent" android:background="#cccccc"> <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center" android:text=" < back" android:textsize="20sp" /> </linearlayout> <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_centerhorizontal="true" android:gravity="center" android:text="a long centered title" android:textsize="22sp" /> </relativelayout> </linearlayout>
i don't think can via xml. calculate @ runtime. put text textview
, calculate width in pixels. default centered, but, if width bigger screenwidth - 2 * backbuttonwidth
, shouldn't centered aligned button edge , trimmed @ end.
Comments
Post a Comment