Created
March 21, 2017 15:44
-
-
Save lugeek/c970765e73abf50925991e61cf2e6fef to your computer and use it in GitHub Desktop.
Android:use xml to center some views,singleline textview and the right view will not disappear
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="200dp" | |
android:orientation="horizontal" | |
tools:context="com.lugeek.dividertest.MainActivity"> | |
<RelativeLayout | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="1" | |
android:background="#eeeeee" | |
android:gravity="center"> | |
<!--contain singleline textview--> | |
<RelativeLayout | |
android:id="@+id/rl" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:gravity="center"> | |
<TextView | |
android:id="@+id/z" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_toLeftOf="@+id/y" | |
android:singleLine="true" | |
android:ellipsize="end" | |
android:text="11111111111"/> | |
<!--the textview below will not disappear--> | |
<TextView | |
android:id="@+id/y" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentRight="true" | |
android:text="元"/> | |
</RelativeLayout> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_below="@id/rl" | |
android:layout_centerHorizontal="true" | |
android:text="11111元"/> | |
</RelativeLayout> | |
<RelativeLayout | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="1"> | |
</RelativeLayout> | |
<RelativeLayout | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="1"> | |
</RelativeLayout> | |
<RelativeLayout | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="1"> | |
</RelativeLayout> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment