why sorry pop up cause of text size? - android

I have a layout with a textview and a button as below.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/info_layout">
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" />
<Button android:id="#+id/butn1"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dip"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/button1" />
</LinearLayout>
The above layout works fine for many languages but for arab its giving sorry pop up, but if i change textSize to 18sp it works fine. Even i tried removing margin from button before changing text size but still the problem raises.I'll set text for text View in java file.So im not understanding what's exact cause for this problem.
01-08 03:09:59.959: E/AndroidRuntime(1803): java.lang.StringIndexOutOfBoundsException: length=75; regionStart=52; regionLength=-18

Related

How to remove internal Image padding (Top, Left and Bottom) of an Android Checkbox

I have a Checkbox in Android with a TextView above it:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/default_margin">
<TextView
android:id="#+id/tv_edit_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:layout_margin="0dp"
android:gravity="center_vertical|center_horizontal"
android:text="#string/edit_checkbox" />
<CheckBox
android:id="#+id/cb_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:checked="true" />
</LinearLayout>
The problem with Checkbox however is that it's internal "Image" got an invisible border around it. How to remove this? I've tried android:padding="-5dp" but this only worked for the right side of the CheckBox for some reason, not the top, left and bottom (my main concern is the Top).
Here is a screenshot of the Checkbox in Eclipse Graphical Layout window:
LineairLayout selected:
Checkbox selected:
In the second picture you can see the Checkbox has some padding around it when you select it. I want to have this removed (especially on the top), so that the space between the Text and the Checkbox is reduced.
Here is a picture when I have padding="-5dp":
Checkbox selected:
PS: If someone knows a solution with just a Checkbox and it's Text-field, so I can removed the LineairLayout and TextView, while still having the Text above the Checkbox I would also appreciate it. A single Checkbox with a custom style and Text is better for performance than a Checkbox inside a LineairLayout with an additional TextView. (I know this is more something for a different question, but I just add it here since it doesn't have a lot of priority. Everything is working already, except for the padding of the Checkbox.)
Ok, I changed the LineairLayout to a RelativeLayout, and than I can change the margin to a minus dp. This is my end result:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/default_margin">
<TextView
android:id="#+id/tv_edit_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:singleLine="false"
android:gravity="center_horizontal"
android:text="#string/edit_checkbox" />
<CheckBox
android:id="#+id/cb_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_edit_checkbox"
android:layout_centerHorizontal="true"
android:layout_marginTop="-10dp"
android:checked="true" />
</RelativeLayout>
This gives the following result:
RelativeLayout selected:
This does change the space between the Text and the Checkbox. For me this is what I want, however it still doesn't explain why the Android Checkbox' internal Image got a padding at its Top, Left and Bottom sides.. Now idea who of Android had this idea, but it was a pretty bad one.. It was better to just use no padding on the internal image and then have some default internal Margin/Padding that can be changed by users..
OR
Edit :
You can also get the same result with LinearLayout :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="0dp"
android:text="For all products"
android:textSize="10sp" />
<CheckBox
android:id="#+id/checkBox_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-10dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:padding="0dp" />
</LinearLayout>

Android popup which resize automatically

today I'm facing an issue with the layouts in android.
This is my goal :
I wan't a popup with a Title, a body containing a scrollView (in case of Big data) and a button.
This is what my layout look like in the big lines:
<RelativeLayout
android:id="#+id/popup_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#FF0000">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Title"/>
<ScrollView
android:id="#+id/body_scrollview"
android:layout_width="wrap_content"//To permit the scrollview to resize depending of the data amount
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/body_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My very long sentence which may take all the screen size and maybe more"/>
</ScrollView>
<Button
android:id="#+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/body_scrollview">
</Button>
</RelativeLayout>
If the text is short, then no issue, the button is still visible, but if the text is very big (I mean bigger than the screen can support) the button disappears.
I could do a bottom alignment with the button and then put the above property inside the scrollView but it will cause the popup to always take all of the height size (even if the text is very small) which is not what I want.
Any idea of how I should do it ?
Thank you by advance.

Truncating a TextView on an AppWidget layout's

people!
Well, after googling for almost two days with no result, I decided to ask here. (It's my first question.)
I'm creating a quotes widget for Android (that shows a random quote each time), so it has two TextViews and a ImageButton to get a new random quote. The first TextView shows the quote text and the second shows the quote's author. And, when the user clicks on the widget, it calls a Activity showing the quote in full screen, with scroll bars if it is needed, and so on.
The thing is that the quote's text sometimes is much long, so I was wanting to ellipsize it. But since the ellipsize doesn't work with more than 2 lines... I'm looking for ideas.
I don't know if it's necessary, but here is the layout code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/laySmall"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="#dimen/widget_margin"
android:background="#drawable/widgetback" >
<ImageButton
android:id="#+id/ibtNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="#null"
android:contentDescription="#string/app_name"
android:src="#drawable/seta" />
<TextView
android:id="#+id/txtWdgQuote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/ibtNext"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="italic"
android:typeface="serif"
android:maxLines="3" />
<TextView
android:id="#+id/txtWdgAuthor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="bold" />
</RelativeLayout>
Basically, I have 3 AppWidgets in this project, showing almost the same thing. All that change are the sizes and font sizes.
So... One idea that I had was using a custom TextView. But in a AppWidget, no way. :/
Another idea was doing something like this:
if (quoteText.length() > something) {
quoteText = quoteText.substring(0, something) + "\"[...]"
}
The problem of this solution is where is the line breaks, because it can change the size of the string that can be showed. For example, let say a string with small words: the lines will break next to the border. Meanwhile a string that has bigger words the line breaks will be further from the border.
So... I don't know what I do. Any ideas, please?
Thanks!
(I'm having problems with the android:layout_margin, so it can be a little smaller, but I didn't have time to work on this yet.

Android TextView text cut off only in Gingerbread

The layouts in my application are built using SDK 16 and I've tested and confirmed they work fine on ICS and JB but GB has the following issue:
In the code below, I'm just trying to create a simple layout with only text. The text keeps getting cut off on Gingerbread at the end of the first line though, instead of going on to the next line. I've tried setting singeLine to false, played around with lines, maxLines, marquee, layoutWeight, changing layoutHeight and layoutWidth to every imaginable combination, etc. This issue truly baffles me.
Code:-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text keeps overflowing"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#33B5E5"
android:paddingTop="6dp"
/>
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text gets cut off when I input a long string like this one"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
/>
</LinearLayout>
</ScrollView>
Also, if I change the theme of the layout to Gingerbread, I get the error:
Failed to find style 'scrollViewStyle' in current theme
Failed to find style 'textViewStyle' in current theme
android.content.res.Resources$NotFoundException
Thanks in advance.
Fixed it myself. Couldn't find out why it was happening but I fixed it by adding the following lines to the code for TextViews:-
android:ellipsize="none"
android:maxLines="10"
android:scrollHorizontally="false"

EditText goes out of the screen sometimes when virtual keyboard shows up

I am developing an application for Android.
I have a simple layout. A CheckBox, a Spinner and a Button at the top, a two line EditText at the Bottom which is displayed when the CheckBox is checked and another EditText which covers the rest of the space in the middle.
The problem is that when I am writing on the big EditText, sometimes the layout goes out of the screen on top and as a result I can't see what I am writing.
As a solution, I can set my layout to resize when the keyboard shows (using android:windowSoftInputMode="adjustResize" on the manifest.xml) but that won't be good since I do not want the 2 EditTexts to share the space left on the screen.
My layout code follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="#+id/button"
android:text="Push"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"/>
<CheckBox android:id="#+id/check_box"
android:text="Check"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<Spinner android:id="#+id/spinner"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText android:id="#+id/text_2"
android:hint="#string/hint_2"
android:inputType="textMultiLine"
android:maxLines="2"
android:gravity="top"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:visibility="gone" />
<EditText android:id="#+id/text_1"
android:hint="#string/hint_1"
android:inputType="textMultiLine"
android:gravity="top"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#id/spinner"
android:layout_above="#id/text_2"
android:layout_alignWithParentIfMissing="true" />
</RelativeLayout>
P.S. This thing happens only on my Wildfire and very rare on the Emulator. A friend's Desire HD didn't have any problem at all. I don;t know if this makes any difference...
Thanks in advance for your help.
Antonis
I have the exact same problem. I've tested and this only happens with EditText in multiline mode and when SoftInputMode is set to adjustPan. This is most probably an Android bug.
The only solution I've found is to remove adjustPan.

Categories

Resources