place textView and editText on the same line in android app - android

i want to place a TextView and EditText on the same line in the following main.xml. How do i do that?
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="#string/txtTotalAmt" android:id="#+id/txtTotalAmt" ></TextView>
<EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/TotalAmt" android:maxLength="6" android:text="0.00" android:inputType="number|numberDecimal"></EditText>
Any help is appreciated.

i believe a surrounding linearLayout with orientation=horizontal is what your after. you could also try using a Tablelayout + Tablerow
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="56px"
android:orientation="horizontal">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/txtTotalAmt"
android:id="#+id/txtTotalAmt" >
</TextView>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/TotalAmt"
android:maxLength="6"
android:text="0.00"
android:inputType="number|numberDecimal">
</EditText>
</LinearLayout>
Hope that helps

Related

How to character-wrap in Android textview without using singleline?

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" />

Make center long TextView in android

How can I make position center of long textView in layout at android.I used android:gravity="center" in layout but it didn't for the TextView has a long text.How can I solve this problem?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/memorialvodafonebackground_2"
android:gravity="center"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ekranda adınız göründükten sonra hastanemizi değerlendirmenizden memnuniyet duyacağız"
android:textColor="#color/black"
android:textSize="40dp" />
</LinearLayout>
Use
android:layout_gravity="center"
for TextView
android:gravity - sets the gravity of the content of the View its used on.
android:layout_gravity - sets the gravity of the View or Layout in its parent.
Hope this helps.
Try Replacing:
android:gravity="center"
to
android:layout_gravity="center"
Like this:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Ekranda adınız göründükten sonra hastanemizi değerlendirmenizden memnuniyet duyacağız"
android:textColor="#color/black"
android:textSize="40sp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ekranda adınız göründükten sonra hastanemizi değerlendirmenizden emnuniyet duyacağız"
android:gravity="center"
android:singleLine="true"
android:textColor="#color/black"
android:textSize="40dp" />

Divide android layout in four columns

I'd like to divide my layout into four columns.
Here my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:id="#+id/recivechallan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="15dip"
android:layout_weight="1"
android:singleLine="true"
android:text="323232"
android:textStyle="bold" />
<TextView
android:id="#+id/reciveDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/recivechallan"
android:layout_marginTop="15dip"
android:layout_toLeftOf="#+id/recivestatus"
android:layout_weight="1"
android:text="5456455565456" />
<TextView
android:id="#+id/recivestatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/reciveDate"
android:layout_toLeftOf="#+id/recivebtn"
android:layout_weight="1"
android:text="Ready"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/recivebtn"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/recivechallan"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="5dip"
android:layout_weight="1"
android:background="#drawable/rounded"
android:singleLine="true"
android:text="Recive" >
</Button>
</RelativeLayout>
Results
Expected
Please suggest me how i can fix this problem
Thanks In Advance
Any Help Is Appreciated
try to use TableLayout with TableRow
example http://www.mkyong.com/android/android-tablelayout-example/
As said in comments, use a LinearLayout instead of a RelativeLayout as your parent container. Then set for all the TextViews and Buttons the weight as you wish, and SET THE WIDTH TO 0dp. That's important ... then it should it work :)

Limit the text in TextView

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.

Android - Ellipsize with right aligned view

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...

Categories

Resources