How can make the width of string the same in Android? -
there 3 strings, each length of string same, there spaces in strings. after fill 3 strings in listview control, find width of 3 row isn't same.
how can make width of string same in android? thanks!
btw, use android studio. min api 9.
string1= "a b" string2= "aa b" string3= "aaa b" listview lv=(listview)findviewbyid(r.id.listview); string[] countries=new string[]{"a b","aa b","aaa b"}; lv.setadapter(new arrayadapter<string>(this, android.r.layout.simple_list_item_1, countries));
unless you're using monospaced font, achieving wanted going quite difficult. non-monospaced fonts has different width each of characters posses.
however, there's workaround using layout arrangement. here's example:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="300dp" android:layout_height="match_parent"> <linearlayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.7"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="a" android:id="@+id/textview2"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="aaa" android:id="@+id/textview4"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="aaaaa" android:id="@+id/textview5"/> </linearlayout> <linearlayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.3"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="b" android:id="@+id/textview3"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="bbb" android:id="@+id/textview6"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="bbbb" android:id="@+id/textview7"/> </linearlayout> </linearlayout>
the above code produce layout this:
Comments
Post a Comment