Half cut text in Spinner Android - android

i have one layout on Android, but if i change size of spinner my text are cut, i try custom background to spinner and try layout default but not resolve.
My XML:
<Spinner
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="40px"
android:layout_marginRight="2dip"
android:layout_weight="1"
android:background="#drawable/spinner_custom"
android:gravity="left|center_vertical"
android:paddingLeft="4dip"
android:textSize="16px" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="40px"
android:layout_marginRight="2dip"
android:layout_weight="1"
android:background="#drawable/spinner_custom"
android:gravity="left|center_vertical"
android:paddingLeft="4dip"
android:textSize="16px" />
</TableRow>
how i can fix it?
Screen with custom background:
http://img814.imageshack.us/img814/8284/spinner.jpg

Is the custom background for your Spinner an image or an xml file? If it's an xml drawable file check that you aren't using padding at the bottom.
Also try changing layout_height value to wrap_content rather than setting to 40px, that may by causing the problem.

Related

add padding to textView with drawable background

Is it possible to add padding into TextView with drawable element on its backround? Or do I need to use Draw 9-patch ?
<TextView
android:layout_width="wrap_content"
android:layout_gravity="bottom|left"
android:layout_marginLeft="5dp"
android:layout_height="85dp"
android:background="#drawable/text_background"
android:id="#+id/counter"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="bold"
android:gravity="center"
android:paddingLeft="2dp"
android:paddingRight="2dp"
/>
This padding settings does not work. For 3-4 digits the background is displayed correctly but when it should adjust (for 5/6 digits) it stays the same.
UPDATE - add image
If You are adding drawable as background then drawablePadding doesn't works.
You just have to give proper padding to you TextView, so that it can handle most of your usecases.
<TextView
android:id="#+id/txt_bankid_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/layout_user_detail"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/spacing_huge"
android:background="#drawable/textview_selector"
android:clickable="true"
android:textAllCaps="true"
android:padding="#dimen/spacing_small"
android:text="#string/login_bankid"
android:textColor="#color/app_background_color"
android:textSize="#dimen/font_normal" />
Never give static height or width to your layouts as you have used in height. It will create problem in different screens and you will face text cutoff.

Space between textview and drawable icon

I'm facing problems with the position of an icon. I've set that icon as drawableLeft of a TextView, this is working fine but, if I set the TextView's gravity to center_horizontal, then a padding space appears between the icon and the text. The code is as follows:
<TextView
style="#style/BaseText.White.Bold"
android:gravity="center_horizontal"
android:drawableStart="#drawable/ic_text"
android:drawableLeft="#drawable/ic_text"
android:text="#string/text"
android:layout_marginBottom="#dimen/margin_small"
android:layout_marginRight="#dimen/margin_big"
android:layout_marginLeft="#dimen/margin_big"
android:padding="0dp"
android:drawablePadding="0dp"/>
What do I have to do to ensure that the icon is shown at the text's left side but horizontally centered?
I've make two screenshots to show you the difference when adding or removing the icon's gravity.
When the textview's gravity is not set, the result is as follows:
But, when the gravity is added, then a padding appears between the text and the icon:
Thanks in advance
Only add android:drawablePadding="10dp" field in your text view refer the coad
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add New Address"
android:textAppearance="#style/Title"
android:id="#+id/tvAddNewAddress"
android:drawablePadding="20dp"
android:layout_weight="1"
android:padding="5dp"
android:textColor="#color/colorAccent"
android:drawableStart="#android:drawable/arrow_down_float"
/>
Try to give android:gravity="center" to Text View. Also add android:layout_width="wrap_content" and android:layout_height="wrap_content" properties in Text View.
Refer this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:drawableLeft="#mipmap/ic_launcher"
android:drawablePadding="0dp"
android:drawableStart="#mipmap/ic_launcher"
android:gravity="center"
android:textSize="22sp"
android:padding="0dp"
android:text="TestingTestingTestingTestingTestingTestingTestingTestingTesting" />
</RelativeLayout>
This is what it showing.

How do you remove the extra inner padding inside a Spinner button in an Android layout?

I am trying to create a Button that looks like a Spinner.
I have done this by creating a Button like this:
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
android:textSize="15sp"
style="?android:attr/spinnerStyle"
android:gravity="center_vertical|center_horizontal" />
The problem is that the text ("default text") inside the Button seems to have extra padding around it, which makes the Button look bloated and expanded in its height.
I thought that setting the layout_height for the button to "wrap_content" would fix this and make the button thinner, but it does not have any effect.
Does anyone know how to make this button's height wrap to the text inside it?
Here is the example code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp" >
<TextView
android:id="#+id/dateLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="Select date:"
android:textSize="15sp" />
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
android:textSize="15sp"
style="?android:attr/spinnerStyle"
android:gravity="center_vertical|center_horizontal" />
</RelativeLayout>
android:gravity="center_vertical|center_horizontal" instead of this you can write
android:gravity="center" but as per your requirment just remove this line.do not add any gravity and change your height size android:layout_height="40dp"
i changed your code
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="35dp"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
style="?android:attr/spinnerStyle"
/>
The padding of this button is decided by the drawable of it. You either need to change the spinner drawable (can be done at runtime) , or provide your own drawable to the given button that would make it look like a spinner, without using the default one

Android layout : imageview is moving along with edittext

Hi, I have a image view and edit text as follows
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="400dp"
android:background="#eeeff4" >
<TextView
android:id="#+id/btextview"
android:layout_width="280px"
android:layout_height="33dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#3B5999"
android:ellipsize="start"
android:gravity="left|center_vertical"
android:paddingLeft="40dp"
android:text="post it"
android:textSize="17sp" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/username"
android:layout_alignParentLeft="true"
android:background="#3B5999"
android:paddingRight="5dp"
android:src="#drawable/book" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/bedittext"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/imageView2"
android:layout_alignTop="#+id/bedittext"
android:src="#drawable/myfb"
android:layout_marginLeft="6dp" />
<EditText
android:id="#+id/bedittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/btextview"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/imageView1"
android:ems="10"
android:hint="say something about this"
android:inputType="textMultiLine"
android:scrollHorizontally="true" >
</EditText>
</RelativeLayout>
when I type in the edittextview multiple line the imageveiw1 also moving along with the edit text, I want the image to be fixed in that position and only the edit text should expand, also how can I make the edittext to get scrolling after 3 lines.
Any suggestion is appreciated.
I type in the edittextview multiple line the imageveiw1 also moving along with the edit text
because you are setting layout_width="wrap_content" to that edit text, so that if you type one character then image shows next to that char, if you type 2nd char then it moves.. ok? to avoid that you can set fixed with or match_parent to that edittext.
2 . how can I make the edittext to get scrolling after 3 lines
just set fixed height to show only three lines and move that edit text into scroll view(this height and width should wrap_content).
You can set the max height of the EditText (android:maxHeight), and set the layout_height of the EditText to wrap_content so it expand till max height

Problem with sizes of EditText and Button in Android

I want to make the edittext width the same size as button. My EditText is currently very small. I use relative layout.
<TextView
android:id="#+id/aha4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dip"
android:text="Vzdevek:"
android:layout_below="#id/aha3" />
<EditText android:id="#+id/nick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/nivo"
android:layout_toRightOf="#id/aha4"/>
<Button android:id="#+id/poslji"
android:text="Pošlji"
android:layout_height="wrap_content"
android:layout_width="20dip"
android:typeface="serif" android:textStyle="bold"
android:layout_alignParentRight="true"
android:layout_below="#id/nivo"
android:layout_toRightOf="#id/nick"/>
What i currently get is this:
alt text http://www.shrani.si/f/1Z/x8/2lWB3f8p/device.png
What is the appropriate layout_width for edittext and button?
As you are using something like a row to show the TextView, EditText and button, you can try to use TableLayout: http://developer.android.com/guide/tutorials/views/hello-tablelayout.html
Also, make sure you set android:layout_width="wrap_content" so that the EditText use as much space as possible.
Try to assign equal weight to both button and edit text
Yeah, you're right about weight.
As a hack you can do this. Not exactly right though.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/aha4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dip"
android:text="Vzdevek:" />
<Button
android:id="#+id/poslji"
android:text="Pošlji"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingLeft="40dip"
android:paddingRight="40dip"
android:typeface="serif"
android:textStyle="bold"
android:layout_alignParentRight="true" />
<EditText
android:id="#+id/nick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#id/aha4"
android:layout_toLeftOf="#id/poslji" />
</RelativeLayout>
I managed to solve it with specifying minWidth and maxWidth for EditText.

Categories

Resources