Android Button widget hyphenation - android

I have a problem with my project. I use android.widget.Button. When word can not fit in one line in the Button then it cut it like this: Somelon>gword (where '>' is new line). How to fix it? And how to create inner padding for the text because the long word touches the button's borders?

You can try below code. Where paddingRight and paddingLeft keep padding of 25dp in right and left. If you want to text on in one line.Then
you can use android:singleLine="true"
<Button
android:id="#+id/she_was_good"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="25dp"
android:paddingLeft="25dp"
android:ellipsize=”marquee”
android:text="#string/im_sorry_lol_str" />
Read this post

Try using the property android:singleLine="true" and android:padding="10dp" to your button widget.

Related

android studio - How do I resize buttons based on text?

I'm making two buttons.
if One button is clicked, the other button's text is changed.
I coded initial status using setText
mBtn.setOnClickListener(this);
mBtn.setText("Connect");
and changing text using
mBtn.setText("Disconnect");
In this case, button's length is fixed initial length.
What can i do?
use this on your layout it will work. remove fixed width first.
android:layout_width="wrap_content"
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Connect"
android:padding="5dp"
/>

How to set line-height textView on Android

I give below attributes that I use textView in my application. ( Green text in middle )
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:text="10/9"
android:id="#+id/estimate_fertility_date"
/>
However, there are spaces like the example picture. I want to set these spaces because when App initialize, It seems awful.
I have researched about 1 hour and I found some answers but They are not which I want answers.
https://stackoverflow.com/a/6864017/2834196
It 's not easy to get absolutely no text padding in a normal TextView. One way is to can set a minus margin for the TextView, or just use textview.setIncludeFontPadding(false) to reduce padding to some degree.
Adding negative values to margin does it help you?
<TextView
android:layout_marginTop="-10dp" />

android textview text direction now responding to changes

I am trying to do the right to left text direction, but I am getting unexpected result (not like the one when I do html css). Here is the code I have for that textview:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="96dp"
android:gravity="right"
android:text="#string/welcomeMsg"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textDirection="rtl"
android:textSize="#dimen/welcomeMsgSize" />
I believe I did everything there is to do. Maybe I forgot something or don't know it. I am pretty new to android. The picture shows the output of the above The problem here is the whitespace preceding the text inside the textview and post the text too. Thanks for your help in advance :)
You should change Textview gravity from "Center" to "Right" or "Left" Depending on your need.
Gravity will set gravity to your text so change it. And also change the text alignment from center to right or left.
android:textSize="#dimen/welcomeMsgSize" there lies the culprit.. reduce the size you specified in that file there..!!

Add multiples images to Edit Text View Android

I have 2 images one is "(" and another ")" how I can add these to EditTextView backgroud and stretch them the size of the EditTextView changes .
I tried to use layer_list without any luck .
Why don't you put those into <ImageView>s and put one to the left and one to the right of the EditText. Something like this:
<RelativeLayout>
<ImageView
android:layout_toLeftOf="#+id/edit_text"/>
<EditText android:id="#id/edit_text"/>
<ImageView
android:layout_toRightOf="#id/edit_text"/>
</RelativeLayout>
Of course you will need to add more attributes to the above, but it is a template for you to get started.
you can use
android:drawableLeft="#android:drawable/left_bracket"
android:drawableRight="#android:drawable/right bracket".
N.B.
by using android:drawableLeft the drawtable to be drawn to the left of the text.
by using android:drawableRigh the drawable to be drawn to the right of the text.
<EditText
android:id="#+id/txtSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="120dip"
android:layout_marginTop="10dip"
android:hint="#string/search_titles"
android:background="#android:color/transparent"
android:drawableRight="#drawable/search_bar_end_right_inactive"
android:drawableLeft="#drawable/search_bar_end_left_inactive"
</EditText>
How I can stretch the images when the textfield is re sizing .?

Split button text into two sections

I am trying to port my WP7 app to android.
Does anyone know how I can layout the text on a single button so that some text appears aligned left and other text appears aligned right? (See below). I need access to be able to dynamically change the percentage number on the right side using code but the text on the right is just static.
Anyone know the answer to this?
The image is here:
http://i.imgur.com/zW7YV.png
Yes you could make it two buttons.
Remove all padding and margin from between them.
Set the same background drawable.
And just ensure when the left is clicked it invokes the right's onPress method (so it looks as if they depress together).
Or wrap the buttons/imageviews/textviews in a layout and perform the onClick on that.
I would use a RelativeLayout for this.
<RelativeLayout
android:width="fill_parent"
android:height="wrap_content"
android:clickable="true"
android:background="#18a2e7"
android:padding="10dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Something" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_align_parentRight="true"
android:text="0%" />
</RelativeLayout>

Categories

Resources