currently I am getting this result for a multiLine text view -
maxLines = 2
If text is -
Hello hfhfhfhfhfhfhhfhfhfhfhfhhfhfhf
Then output is :
But I need it like this :
Please help me to get this result :)
XML is
<TextView
android:id="#+id/user_name"
style="#style/default_text_font_face"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:scrollHorizontally="true"
android:maxLines="2"
android:text="Hello hffffffhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhhfhfhhfhfhfhfhhfhfhfhhfhfhfhfhhfhfhfhfhhfhfhfhfhhfhfhfhfhhfhf"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white" />
Use
android:layout_width="match_parent"
to your TextView
EDIT1
Try the following way
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#535353"
android:textColor="#ffffff"
android:maxLines="2"
android:text="Best Effffffffffffffffffffffffffffffff\nfffffffffffffffffffffffffffffffffffffff"
android:textSize="20dp"/>
</LinearLayout>
Output
I hope this may helps you
you have use below property..
android:maxWidth="size"
Replace the size with the size you prefer. For example, 100dip.
UpDate :
xml file
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:maxLines="2"
android:maxWidth="50dip"
android:text="Best Efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15dp" />
Output :
UpDate 2 :
using match_parent.
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:maxLines="2"
android:maxWidth="50dip"
android:text="Best Efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15dp" />
output :
Related
I have a table format containing columns and multiple rows like
M.wt
D.wt
Cs.wt
12.000
2.340
0.997
Here M.wt ,D.wt and Cs.wt is the heading column and the values are has shown,i am not able to align the values considering decimal point one below the other,i am getting like
12.000
2.566
5.666
My layout is like code is like
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:id="#+id/textView21"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textColor="#000000"
android:textStyle="bold"
android:typeface="serif"
/>
<TextView
android:id="#+id/textView22"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textColor="#000000"
android:textStyle="bold"
android:typeface="serif"
/>
</LinearLayout>
How to handle this,it should be handle in layout or java file ?
My screen is actually like so:
You need to format the text that is you are setting to the TextView for the 3 decimal points like below
mwt = 0.2f;
textView2 = (TextView)findViewById(R.id. textView2);
textView2.setText(String.format("%.3f",mwt));
dwt = 0.1f;
textView21 = (TextView)findViewById(R.id.textView21);
textView2.setText(String.format("%.3f",dwt));
Add the gravity property as end and your text view will be
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold"
android:typeface="serif" />
I have a textview in xml file. When a text is set in java file, if the 2nd String is too long, for example: "Hello Worlddddddddddddddddddddddddddddddddddddddddddddd", the 2nd word is not visible. It should be only one line and should not use the android:singleLine How can I solve it? Thanks in advance for the help. :)
<TextView
android:id="#+id/txtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:maxLines="1"
android:textColor="#color/white" />
if you without using singline, you can set height and weight.
android:scrollHorizontally="false"
ex :
<TextView
android:id="#+id/text"
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:scrollHorizontally="false"
android:layout_height="15dp"/>
Use the XML below or refer to this SO article as this is what you really need.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:ellipsize="end"
android:singleLine="true"
android:gravity="right|center_vertical"
android:maxLines="1"/>
You can use elipsize property of textview
<TextView
android:id="#+id/txtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:maxLines="1"
android:textColor="#color/white"
android:ellipsize="end" />
This is a simple question but its kicking my butt all around xml land.
All I want to do is to have the two edit text fields separated by a colon and to have the colon be centered like the following:
00:30
Right now when it displays the colon is slightly lower than the 00 and 30 of the edit text fields
I have tried using android:layout_marginBottom= "10dp" but that doesn't work. Any ideas? Thanks
Here is my code:
<EditText
android:id="#+id/edit_minute"
android:layout_width="wrap_content"
android:layout_height="85dp"
android:layout_below="#+id/text_minute"
android:layout_marginLeft="45sp"
android:inputType="number"
android:text="#string/edit_minute"
android:textColor="#0D4F8B"
android:textSize="70sp"
android:textStyle="bold" />
<TextView
android:id="#+id/text_colon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/edit_minute"
android:layout_below="#+id/text_minute"
android:textAlignment="center"
android:text="#string/text_colon"
android:textSize="70sp"
android:textStyle="bold" />
<EditText
android:id="#+id/edit_second"
android:layout_width="105dp"
android:layout_height="85dp"
android:layout_below="#+id/text_minute"
android:layout_toRightOf="#+id/text_colon"
android:inputType="number"
android:text="#string/edit_second"
android:textColor="#0D4F8B"
android:textSize="70sp"
android:textStyle="bold" />
Put Layout_height of Both edittext to wrapcontent without giving a specific height then the three views would be aligned.....
<EditText
android:id="#+id/edit_minute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text_minute"
android:layout_marginLeft="45sp"
android:inputType="number"
android:text="08"
android:textColor="#0D4F8B"
android:textSize="70sp"
android:textStyle="bold" />
<TextView
android:id="#+id/text_colon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/edit_minute"
android:layout_below="#+id/text_minute"
android:textAlignment="center"
android:text=":"
android:textSize="70sp"
android:textStyle="bold" />
<EditText
android:id="#+id/edit_second"
android:layout_width="105dp"
android:layout_height="wrap_content"
android:layout_below="#+id/text_minute"
android:layout_toRightOf="#+id/text_colon"
android:inputType="number"
android:text="30"
android:textColor="#0D4F8B"
android:textSize="70sp"
android:textStyle="bold" />
I would first put them all in a RelativeLayout, and place this layout under "text_minute".
Then in the following I centered all, and the colon's height is adjusted using the attributes layout_alignTop and layout_alignBottom that force the TextView to follow the first EditText height:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text_minute" >
<EditText
android:id="#+id/edit_minute"
android:layout_width="wrap_content"
android:layout_height="85dp"
android:layout_toLeftOf="#+id/text_colon"
android:inputType="number"
android:text="#string/edit_minute"
android:textColor="#0D4F8B"
android:textSize="70sp"
android:textStyle="bold" />
<TextView
android:id="#+id/text_colon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_alignTop="#+id/edit_minute"
android:layout_alignBottom="#+id/edit_minute"
android:gravity="center_horizontal"
android:text="#string/text_colon"
android:textSize="70sp"
android:textStyle="bold" />
<EditText
android:id="#+id/edit_second"
android:layout_width="wrap_content"
android:layout_height="85dp"
android:layout_toRightOf="#+id/text_colon"
android:inputType="number"
android:text="#string/edit_second"
android:textColor="#0D4F8B"
android:textSize="70sp"
android:textStyle="bold" />
</RelativeLayout>
You can place your EditText TextView and EditText all in a LinearLayout and use android:baselineAligned and android:baselineAlignedChildIndex.
If you require your parent view is a RelativeLayout then you can use android:layout_alignBaseline on each of the child views.
This is my code:
<TextView
android:id="#+id/error_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:gravity="center"
android:drawableRight="#drawable/error_image"
android:visibility="invisible"
android:textColor="#aa0000"
android:textStyle="bold"
android:textSize="16dp"/>
There is space between image and text and I want reduce this space, how can I do it?
As you had set android:layout_width="match_parent", TextView took all the width so the drawablePadding which you set will not work. So you need to set android:layout_width="wrap_content".
Try following code :
<TextView
android:id="#+id/error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="0dp"
android:layout_marginBottom="2dp"
android:drawableRight="#drawable/ic_launcher"
android:gravity="center"
android:textColor="#aa0000"
android:textSize="16dp"
android:text="adsfasdfa"
android:textStyle="bold"
android:visibility="invisible" />
You should set the property android:drawablePadding="0dp"
Or in your java code, call textView.setCompoundDrawablePadding(0);
Is there a way to bold the text in a TextView via XML?
<TextView
android:textSize="12dip"
android:textAppearance="bold" -> ??
</TextView>
Thanks
I have a project in which I have the following TextView :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="#string/app_name"
android:layout_gravity="center"
/>
So, I'm guessing you need to use android:textStyle
just use
android:textStyle="bold"
Example:
use: android:textStyle="bold"
<TextView
android:id="#+id/txtVelocidade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/txtlatitude"
android:layout_centerHorizontal="true"
android:layout_marginBottom="34dp"
android:textStyle="bold"
android:text="Aguardando GPS"
android:textAppearance="?android:attr/textAppearanceLarge" />
Use android:textStyle="bold"
4 ways to make Android TextView Bold
like this
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="12dip"
android:textStyle="bold"
/>
There are many ways to make Android TextView bold.
use textstyle property as bold
android:textStyle = "bold";
Just you need to use
//for bold
android:textStyle="bold"
//for italic
android:textStyle="italic"
//for normal
android:textStyle="normal"
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="#string/userName"
android:layout_gravity="left"
android:textSize="16sp"
/>