I have a textview Which Contains some text changes dynamically within the UI like below
layout:
<TableRow android:weightSum="2" >
<ImageButton
android:id="#+id/archive"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="90dp"
android:background="#drawable/archive" />
<ImageButton
android:id="#+id/facebook"
android:layout_width="-200dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/facebook" />
</TableRow>
<TableRow android:layout_marginTop="2dp" >
<TextView
android:id="#+id/titlename1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="4dp"
android:text="#string/nowplaying"
android:textColor="#000000"
android:textSize="12sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/titlename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:ellipsize="none"
android:gravity="right"
android:maxEms="25"
android:maxLines="1"
android:scrollHorizontally="false"
android:textColor="#000000"
android:textSize="11dp" />
</TableRow>
<TableRow android:layout_marginTop="2dp" >
<FrameLayout
android:id="#+id/mainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="0dp"
android:orientation="vertical" >
<ImageButton
android:id="#+id/playbtn"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/play" />
<ImageButton
android:id="#+id/pausebtn"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/pause" />
</FrameLayout>
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/mainlayout"
android:layout_marginLeft="-203dp"
android:layout_marginRight="0dp" />
</TableRow>
My Problem is that when i execute my Program,my layout output:
Imagebutton1 ImageButton2
NowPlaying: SongDetails
Play/Pause SeekBar
Problem is If my SongDetails text lenght Contains 2 or 3 lines My layout is getting Disturbed?Could any one Suggest?My Requirement is to limit the text like
Song Detailssss etc......in a Same Row
Simply use android:singleLine="true", and android:ellipsize="end". So You need to update TextView code as
<TextView
.....
....
android:ellipsize="end"
android:singleLine="true" />
Refrences :
android:singleLine
android:ellipsize
try to use
android:singleLine="true"
in your textview
also you can set marquee.
Note that this marquee will work if your text line is longer then your screen size only.
Try setting android:ellipsize paremeter to "end"
Like this
android:ellipsize="end"
Try setting android:ellipsize paremeter to "end" if you want to trim the content at the end.
android:ellipsize="end"
Just remove wrap_content. That should work(haven't tried it myself recently, but I used it a couple of months ago).
Otherwise, you could cut the text manually in Java, and cut it at the first newline found.
Related
Here is my layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_marginStart="20dp"
android:gravity="center_vertical|start"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18.9dp"
android:lineSpacingExtra="64sp"
android:textColor="#484848"
android:textSize="16sp"
tools:text="அனைத்து அனைத்துஅனைத்து" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:lineSpacingExtra="64sp"
android:text="0"
android:textAlignment="center"
android:textColor="#color/red_500"
android:textSize="14sp" />
</LinearLayout>
All other languages are working fine, except tamil language is very big.
I need an icon at beginning and sometimes it show number of notifications at end. So I need to set ellipsize to text on middle.
How to achieve this?
you can use android:ellipsize atrribute to do that.
like this :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18.9dp"
android:lineSpacingExtra="64sp"
android:textColor="#484848"
android:textSize="16sp"
android:ellipsize="end"
android:maxLines="1"
tools:text="அனைத்து அனைத்துஅனைத்து" />
note: don't forget to use android:maxLines attribute to set the line number of your text.
I have the following layout wrapped inside a linearlayout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<Lato_TextView
android:id="#+id/person_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="Aadil Holy"
android:textColor="#000000"
android:textSize="16sp"
exaprojects:fontName="Lato-Regular.ttf" />
<Lato_TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="05dp"
android:layout_marginStart="05dp"
android:gravity="start|center"
android:text="(#884)"
android:textSize="14sp"
exaprojects:fontName="Lato-LightItalic.ttf" />
</LinearLayout>
The views are laid in horizontal alignment inside a cardview, the problem here is if the text in person_name is too long, the text in textView2 gets clipped and is shown vertically, which runs this layout. How to overcome this?
Try using RelativeLayout instead. Example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:id="#+id/person_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="Aadil Holy"
android:textColor="#000000"
android:textSize="16sp"
android:layout_toLeftOf="#+id/textView2"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="05dp"
android:layout_marginStart="05dp"
android:gravity="start|center"
android:text="(#884)"
android:textSize="14sp"
android:layout_alignParentRight="true" />
First approach:
android:ems or setEms(n)
"Makes the TextView be exactly this many ems wide"
Note : but only when the layout_width is set to "wrap_content". Other layout_width values override the ems width setting.
You can also try this:
android:singleLine="false"
Basically, what I want is to have the EditText fill in the rest of the field. Since the first label is a wrap_content and the last item is just an imageview. I am not able to get the EditText to fill in the rest. Originally, I had it in a LinearLayou, but this wasn't working for me either.
Here's the layout so far:
<RelativeLayout
android:id="#+id/email_form"
android:layout_width="match_parent"
android:layout_height="#dimen/input_height"
android:layout_marginTop="#dimen/t_button_margin"
android:background="#drawable/form_edittext_background"
android:orientation="horizontal"
android:padding="#dimen/input_padding" >
<TextView
android:id="#+id/email_lbl"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:maxLines="2"
android:maxWidth="150dp"
android:layout_marginLeft="#dimen/input_label_margin_left"
android:text="adsadasdsa asd asdasd asdas dasd asd asdasda s"
android:layout_alignParentLeft="true"
android:textColor="#color/o_text"
android:textSize="#dimen/input_label_font" />
<EditText
android:id="#+id/email_txt"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#color/o_form_bg"
android:cursorVisible="true"
android:ems="10"
android:focusable="true"
android:gravity="right"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:text="aasdsd"
android:nextFocusDown="#+id/passwordTxt"
android:layout_toLeftOf="#+id/email_lbl"
android:layout_toRightOf="#+id/chk_email"
android:padding="1dp"
android:textColor="#color/dark"
android:layout_centerVertical="true"
android:textCursorDrawable="#null"
android:textSize="#dimen/o_font_input" />
<ImageView
android:id="#+id/chk_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="3dp"
android:contentDescription="#string/uplay"
android:src="#drawable/i_check2"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
It seems that you swapped toRightOf and toLeftOf
Try this :
<EditText
android:id="#+id/email_txt"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#color/o_form_bg"
android:cursorVisible="true"
android:ems="10"
android:focusable="true"
android:gravity="right"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:text="aasdsd"
android:nextFocusDown="#+id/passwordTxt"
android:layout_toLeftOf="#+id/chk_email"
android:layout_toRightOf="#+id/email_lbl"
android:padding="1dp"
android:textColor="#color/dark"
android:layout_centerVertical="true"
android:textCursorDrawable="#null"
android:textSize="#dimen/o_font_input" />
Have you tried this?
<EditText
android:layout_gravity="fill_horizontal"
... />
Note: fill_parent is deprecated and is a synonym for match_parent so it's not what you want here.
Have you tried using Layout_weight attribute.
set android:layout_weight = "0" for the other 2 views and android:layout_weight = "1" for the editText which should take all space
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" />
How can I achieve the following layout, with TextView being a TextView with ellipsize end and View being wrap_content and immediately to the right of TextView ?
Here are three examples of how the layout should behave, with different TextView width :
|[TextView] [View] |
|[TextView TextView] [View] |
|[TextView TextView T...] [View]|
[Edit]
The following TableLayout gives the correct behaviour :
<TableLayout
android:id="#+id/upper_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/alert_button"
android:shrinkColumns="0"
android:stretchColumns="2" >
<TableRow>
<TextView
android:id="#+id/name_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:includeFontPadding="false"
android:lines="1"
android:paddingTop="2dp"
android:scrollHorizontally="true" />
<TextView
android:id="#+id/unread_count_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:includeFontPadding="false"
android:paddingBottom="0dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp" />
</TableRow>
</TableLayout>
The TableLayout uses 3 columns, the last being the hack : the strechColumns property makes it take all available space, so the second TextView is always immediatly to the right of the first one.
The first TextView ellipsize correctly because of the shrinkColumns property.
However, I don't like the idea of using a TableLayout to achieve that.
Does anybody know a better way ?
Thanks
Try this (I cannot check it now, but to my point of view it should work):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dip" >
<TextView
android:id="#+id/my_txtvw_txtvw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ellipsize="marquee"
android:maxLines="1" />
<TextView
android:id="#+id/my_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/my_txtvw_txtvw"
android:maxLines="1" />
</RelativeLayout>
Try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/my_view"
android:ellipsize="end"
android:maxLines="1"
android:layout_alignParentLeft="true"
android:text="blablabla blablabla"
android:layout_centerVertical="true"
android:gravity="center_vertical|left" />
<TextView
android:id="#+id/my_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:maxLines="1" />
</RelativeLayout>
I'm not sure if you want android:ellipsize="end" or android:ellipsize="marquee". I think the layout will work fine to you, just replace the ellipsize value id needed.
Let me know about your progress...