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" />
Related
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 :
I'm trying to put an N (new) badge at the end of the Textview. But Android Studio gives me that two Textviews, hashtag_list_row_title and hashtag_list_row_new can overlap if one Textview contains some lengthy string.
In production environment, it's not likely that hashtag_list_row_title is long, but I want to prevent two Textviews from being overlapped. How can I achieve this?
I prefer the way hashtag_list_row_new has priority over hashtag_list_row_title because that's more natural way to display an N badge.
So far my code is as follows.
list_row.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/hashtag_list_row_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_list_row_selector" >
<RelativeLayout
android:id="#+id/hashtag_list_row_title_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="24dp"
android:layout_toLeftOf="#+id/hashtag_list_row_post_count"
android:layout_toStartOf="#+id/hashtag_list_row_post_count">
<TextView
android:id="#+id/hashtag_list_row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:textColor="#color/hotspot_list_row_title"
android:textSize="16sp"
android:textStyle="bold"
android:text="asdfasdfsadfsadfsfsfsafasdfsafsfasfasfasf" />
<TextView
android:id="#+id/hashtag_list_row_new"
android:layout_toRightOf="#+id/hashtag_list_row_title"
android:layout_toEndOf="#+id/hashtag_list_row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/red"
android:textStyle="bold"
android:layout_marginTop="2dp"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:text="#string/N" />
</RelativeLayout>
<TextView
android:id="#+id/hashtag_list_row_post_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#drawable/btn_post_normal"
android:gravity="center"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#787878"
android:textSize="12sp"
android:textStyle="bold" />
<View
android:id="#+id/hashtag_list_row_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/hashtag_list_row_title_layout"
android:layout_marginTop="24dp"
android:background="#color/bg_horizontal_divider" />
</RelativeLayout>
Edit
Textview on the right side should place right next to the left one, which has varying length. And I want to prevent the situation where the left one gets longer beyond certain length so that the right one is hidden, or overlapped, or whatever.
It should look as below.
| (text) N (empty space empty)|
| (more text) N (empty space) |
| (more text more more...) N |
Edit 2
I want the left TextView to be ellipsized when it's beyond the width of the row except for N badge. I want this.
I don't want this.
Edit 3
N badge should not be placed on the right side all the time. I want the badge to be placed right next to the left TextView when the length is shorter than horizontal width.
It's good.
It's no go.
Ran into the same problem.
What you want is the right side TextView to have:
android:layout_toEndOf="#+id/member_count"
The ID being the ID of the left side TextView.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="#+id/member_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textStyle="bold"
android:text="10"
android:textSize="16sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:layout_toEndOf="#+id/member_count"
android:text="Members"
android:textSize="16sp"/>
</RelativeLayout>
Try something like below.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/hashtag_list_row_root"
android:background="#drawable/bg_list_row_selector"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/hashtag_list_row_title_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="24dp"
android:layout_toLeftOf="#+id/hashtag_list_row_post_count"
android:layout_toStartOf="#+id/hashtag_list_row_post_count">
<TextView
android:singleLine="true"
android:id="#+id/hashtag_list_row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:textColor="#color/hotspot_list_row_title"
android:textSize="16sp"
android:textStyle="bold"
android:text="asdfasdfsadfsadfsfsfsafasdfsafsfasfasfasf" />
</RelativeLayout>
<TextView
android:id="#+id/hashtag_list_row_post_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#drawable/btn_post_normal"
android:gravity="center"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#787878"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:layout_centerVertical="true"
android:id="#+id/hashtag_list_row_new"
android:layout_toLeftOf="#+id/hashtag_list_row_post_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/red"
android:textStyle="bold"
android:layout_marginTop="2dp"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:text="#string/N" />
<View
android:id="#+id/hashtag_list_row_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/hashtag_list_row_title_layout"
android:layout_marginTop="24dp"
android:background="#color/bg_horizontal_divider" />
</RelativeLayout>
Result will be something similar like below. I had to remove some attributes that was pointing to resources that my project didn't have, so below figure is just a mock up. The code is updated to fit you.
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.
I am developing an app. In that I am getting data from webservice and I am inserting it in TextView. But, the alignment of the textview is getting scrambled. Please check the image.
First 3 rows(black colored) is in proper order, from the 4th it is scrambled. I googled on it so many times but not getting the exact solution as I wanted.
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
>
<TextView
android:id="#+id/schedule_1_textView_day_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="KKR"
android:layout_weight="1.5"
android:layout_marginTop="10dp"
android:textColor="#color/Black"
android:textSize="7sp"
/>
<TextView
android:id="#+id/schedule_1_textView_matchno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:layout_weight="1.5"
android:layout_marginTop="10dp"
android:textColor="#color/Black"
android:textSize="7sp"
/>
<TextView
android:id="#+id/schedule_1_textView_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="6"
android:textColor="#color/Black"
android:textSize="7sp"
/>
<TextView
android:id="#+id/schedule_1_textView_team1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="4"
android:textSize="7sp"
android:textColor="#color/Black"
/>
<TextView
android:id="#+id/schedule_1_textView_team2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:textColor="#color/Black"
android:textSize="7sp"
/>
<TextView
android:id="#+id/schedule_1_textView_venue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:layout_marginTop="10dp"
android:textColor="#color/Black"
android:textSize="7sp"
/>
<TextView
android:id="#+id/schedule_1_textView_blank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"
android:layout_marginTop="20dp"
android:textColor="#color/Black"
android:textSize="6sp"
android:visibility="invisible"
/>
</LinearLayout>
Try this..
You forget to add android:layout_weight="1" for below two TextView Use android:singleLine="true" for all TextView
<TextView
android:id="#+id/schedule_1_textView_venue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:text="6"
android:layout_marginTop="10dp"
android:textColor="#color/Black"
android:textSize="7sp"
/>
<TextView
android:id="#+id/schedule_1_textView_blank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:text="B"
android:layout_marginTop="20dp"
android:textColor="#color/Black"
android:textSize="6sp"
android:visibility="invisible"
/>
you might wanna assigh android:layout_weight property to the TextViews like:
<TextView
android:id="#+id/schedule_1_textView_venue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="6"
android:layout_marginTop="10dp"
android:textColor="#color/Black"
android:textSize="7sp" />
you will need to assign weight according to your requirement. i.e for bigger views you want to assign higher values.
[EDIT] and for the last TextView you may want to set android:layout_gravity="center|right" and android:layout_gravity="center|left" for the first for the text alignment for the rest you should use android:layout_gravity="center"
Add gravity to your TextView like:
android:gravity="center_vertical|center_horizontal"
change gravity to left, right or center as you need...
have you tried adding weight to schedule_1_textView_venue?
It's a little more work, but did you try using TableLayout? This is very useful tutorial that can help you organizing the correct order of views.
EDIT: I think i know what causes the mismatch of the TextViews. It comes from the different length of the values in your last column named VENUE. Take for example the values HYDEBARAD and DELHI - the first one is much longer than the second which makes all the TextViews on the row to go left. I am sure that if you put identical padding to the TextViews you will align them. For example: take your TextViews in MATCH column and write the following: myTextView.setPadding(40, 0, 0, 0) (padding on the left side) this will put them exactly in a straight row. Do the same with the rest TextViews with the proper padding value, take into consideration the length of the values in the other columns... It is a little bit tricky though. :)
I have this layout inside of a RelativeLayout:
<LinearLayout
android:id="#+id/llWatchItemCommentButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/myMasterCat_Item"
style="#style/DropShadowEffect"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="99"
android:shadowColor="#ffffff"
android:text="Item"
android:textColor="#515b61"
android:textSize="22sp" />
<ImageView
android:id="#+id/bFollowComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/featured_button_selector"
android:padding="5dp"
android:src="#drawable/comment" />
</LinearLayout>
<TextView
android:id="#+id/myMastCat_Cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/llWatchItemCommentButton"
android:layout_alignLeft="#+id/llWatchItemCommentButton"
android:layout_marginLeft="10dp"
android:text="MasterCat"
android:textColor="#666"
android:textSize="16sp" />
Essentially, if that TextView in the Layout becomes two lines, it will overlap with the TextView positioned below theLinearLayout`.
Is there an attribute perhaps that could correct this? As in, I want the bottom TextView to be below the entire LinearLayout at all times, even if it begins to grow. Right now, the position appears fixed.
Have you tried the following:
<TextView
android:id="#+id/myMastCat_Cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/llWatchItemCommentButton" //add this line in
android:layout_alignBottom="#+id/llWatchItemCommentButton"
android:layout_alignLeft="#+id/llWatchItemCommentButton"
android:layout_marginLeft="10dp"
android:text="MasterCat"
android:textColor="#666"
android:textSize="16sp" />