-1

I want to set three textview contain in same row. I use LinearLayout . Unable to set properly.

Here is my XML :

<LinearLayout
    android:id="@+id/tableRow3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal" >

        <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="@string/or"
    android:textSize="25sp"
    android:singleLine="true"
     /> 

        <TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:textColor="#54d66a"
    android:text="@string/login"
    android:textSize="25sp"
   android:textAppearance="?android:attr/textAppearanceLarge"
     /> 

        <TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"

    android:text="@string/email_details"
    android:textSize="25sp"

     /> 


  </LinearLayout>  

May I know what is the correct way to achieve my objective?Maybe this question too basic, but i did't find any suitable solution.Please Help me out.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198

8 Answers8

2

you just need to remove android:ems="10" from TextView it will automatically in single line. check this code.

 <TableRow
    android:id="@+id/tableRow3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="@string/or"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/login"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#54d66a"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/email_details"
        android:textSize="25sp" />
</TableRow>
SilentKiller
  • 6,944
  • 6
  • 40
  • 75
  • 1
    @Amiya you should not ask for upvote like this. this is oppose to StackOverflow rules. and if answer is helpful to you and you got the solution you should accept the useful answer – SilentKiller Mar 31 '14 at 08:31
1

There is no need for 3 TextView's. You could combine the whole line into a single TextView. There are two possible solutions. 1. You can use SpannableString to achieve the same effect. See this post for more information on Spannables. 2. You can decorate that String using Html tags. See this post

Community
  • 1
  • 1
Vino
  • 1,544
  • 1
  • 18
  • 26
1

If you just want to achieve a different text color you can use HTML tags, for example:

String html = "or <font color="green">login </font> with your email address";
myTextView.setText(Html.fromHtml(html), TextView.BufferType.SPANNABLE);
kstachniuk
  • 358
  • 1
  • 4
0

You should add in horizontal linear-layout if you want add just one line.

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/tabs_layout"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
android:orientation="horizontal"
>
 <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"        
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/or"
android:textSize="25sp"
android:singleLine="true"
 /> 

 <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#54d66a"
android:text="@string/login"
android:textSize="25sp"
android:textAppearance="?android:attr/textAppearanceLarge"
 /> 

    <TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/email_details"
android:textSize="25sp"

 /> 
  </LinearLayout>
Mayur Raval
  • 3,250
  • 6
  • 34
  • 57
0

I found the solution you don't mention the ems value in your layout i modified your layout use this one...

     <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" >

        <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="or"
    android1:paddingRight="5dp"
    android:textSize="25sp"
    android:singleLine="true"
     /> 

        <TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#54d66a"
    android:text="login"
    android1:paddingRight="5dp"
    android:textSize="25sp"
    android:textAppearance="?android:attr/textAppearanceLarge"
     /> 

        <TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"   
    android:text="with your e-mail address"
    android:textSize="25sp"

     /> 


  </TableRow>  
Naveen Kumar Kuppan
  • 1,424
  • 1
  • 10
  • 12
0

Use below code:

tvWeblink = ((TextView) findViewById(R.id.textView1));
tvWeblink.setClickable(true);
tvWeblink.setMovementMethod(LinkMovementMethod.getInstance());
String text = "or <a href=\"<your_login_url>\"> login </a> with your e-mail address.";
tvWeblink.setText(Html.fromHtml(text));
Manish Dubey
  • 4,206
  • 8
  • 36
  • 65
0

Using Spannable String:-

TextView textView = (TextView)findViewById(R.id.mytextview01);
Spannable wordtoSpan = new SpannableString("or Login with your e-mail address");        
wordtoSpan.setSpan(new ForegroundColorSpan(Color.GREEN), 3, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //3- start of character 8- end of character to apply forground color
textView.setText(wordtoSpan);

Using HTML String:-

For better language compatibility support add your string inside res/values/strings

values/strings

<string name="Message">or<![CDATA[<font color='green'> Login</font>]]> with email address</string>

Snippet:

textView.setText(Html.fromHtml(getString(R.strings.Message)));
Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
0
Check this one
<LinearLayout
    android:id="@+id/tableRow3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:weightSum="3" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true"
        android:text="or"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ems="10"
        android:text="login"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#54d66a"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ems="10"
        android:text="detail"
        android:textSize="25sp" />
</LinearLayout>
Palak
  • 574
  • 2
  • 10