android - RelativeLayout with two textviews on one horizontal line with ellipsis support -
i trying setup relativelayout 2 textview shown on 1 line. first textview should aligned left. second textview should aligned right. if second textview text expand overlap first textview want ellipsize text in middle. don't want ellipsize first textview.
this have come with. problem second textview directly right of first textview instead of being aligned far right. seems cannot use alignparentright , torightof @ same time.
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:id="@+id/left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:textappearance="?android:attr/textappearancemedium" android:text="[detailedtype]"/> <textview android:id="@+id/right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/left" android:layout_alignparenttop="true" android:layout_alignparentright="true" android:ellipsize="middle" android:singleline="true" android:textappearance="?android:attr/textappearancemedium" android:text="[customername]"/> </relativelayout>
the basic idea achieve id add dummy invisible view in horizontal center of relativelayout
, tell left textview
to left of , right textview
to right of it... see below
about problem aligning right, should stretch textview take half of screen , set android:gravity="right"
on textview
<?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"> <view android:id="@+id/dummy" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_centerhorizontal="true" /> <textview android:id="@+id/left" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_toleftof="@id/dummy" android:text="[detailedtype]" android:textappearance="?android:attr/textappearancemedium"/> <textview android:id="@+id/right" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@id/left" android:gravity="right" android:ellipsize="middle" android:singleline="true" android:text="[customername]" android:textappearance="?android:attr/textappearancemedium"/> </relativelayout>
but can use linerlayout
job
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <textview android:id="@+id/left" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="[detailedtype]" android:textappearance="?android:attr/textappearancemedium"/> <textview android:id="@+id/right" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:ellipsize="middle" android:singleline="true" android:text="[customername]" android:textappearance="?android:attr/textappearancemedium"/> </linearlayout>
Comments
Post a Comment