In my android application I want to implement 2 text fields in the same line. if the text is so long okay to go to next line. So I used horizontal leaner layout and added the 2 text fields.
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout1">
<TextView android:text="TextView" android:id="@+id/textView2" android:开发者_开发百科layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="TextView" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView></LinearLayout>
[Eg: TextView1, TextView2]
The problem is when the text of TextView1 is bit long it still try to print all in one line and mess up.
The result I want is,
if
TextView1 = aaaaaaaaaaaaaaaaaaaa & TextView2 = bbbbbbbbbbbbbbbbb
aaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbb
bbbbbb
does anyone one have any idea of how to do this. Thank you.
try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is the textview1 in the linearlayout"
android:layout_weight="1"
android:background="#0a30aa"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="this is textview2 in the linearlayout"
android:layout_weight="1"
android:background="#990099"
/>
</LinearLayout>
Just add
android:layout_weight="1"
property to your textviews that will be do the job.
精彩评论