Android text gets clipped on some devices - android

I am facing an issue in one phone (till yet). My app uses Hindi fonts. It shows well on emulator, tab, many other phones too. But one of the phone which I am using for testing purpose is showing the text going cut from sides.
I tried almost everything for putting it in the right order but none worked. Here posting the screenshots of two of my test phones and the text.
The screenshot with error:
The screenshot of other phones: and the expected one too:
What could be the reason and how can I solve it? Please let me know!!
TextView configs I am using:
<TextView
android:id="#+id/A_lbl_mandir"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/Abt_mandir"
android:textAlignment="center"
android:textColor="#80000A"
android:textSize="35sp" />
EDIT: My complete activity xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:id="#+id/text"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="#string/hello_world" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/text" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:padding="5sp"
android:text="#string/test"/>
</ScrollView>
</RelativeLayout>
I have tried and deleted many other things especially for this phone. But unable to solve the issue!

this occurs in 4.1.2 and its documented as a bug in Google which they have fixed in 4.2.
https://code.google.com/p/android/issues/detail?id=34432
This happens with unicode fonts where the Android OS is not able to calculate the length of the text.

try this.
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_below="#id/text"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="left"
android:padding="5sp"
android:text="#string/test"/>
</ScrollView>

All right! Found another phone with same issue. In that phone too, the text was clipped. I guess there is some problem with the phone. Because even popular apps like Whatsapp has got the same problem on that device. The Hindi text was cut same as shown in the images above.
Possible fix for that issue: (if someone gets that n what I am doing now.) I realised that browser shows the hindi fonts well on that. So better make a native app on html, javascript especially for such devices and view the HTML using WebView.The application will get a little slow but we have to do it Until we get the actual problem creating it.
Please note: this is not a solution, but a fix to make that work. Better known as "JUGAAD" in hindi.

On some phones (specially on Samsung ones) some custom fonts are cuted off (or clipped). I had this with custom italic font. Some say that you can edit font to add some kind of padding (i can't confirm that because my lack of knowledge of editing fonts) but:
- EditText/TextView add some padding from xml
- Ellipsize (on some devices messing with this helps displaying text correctly)
Also could you post screenshot with enabled developer options to draw layout bounds, this could help to resolve your problem if above solutions won't help

Related

Android Layout is messed on Pixel and Nexus phones

I am having this weird behaviour in the images below only on any Google phone, old or new, does not matter it just appears mistakenly. The sad thing is that it appears as expected on the rest of all phones. The annoying thing is that it appears correctly in the design as it appears in the image but everyone knows design never reflect reality in xml, the other annoying thing is that it is so simple, the root is the CoordinatorLayout and the text is just in the root :/
Here is the xml code
<androidx.coordinatorlayout.widget.CoordinatorLayout(This layout is the )
android:layout_width="match_parent"
android:layout_height="match_parent"
app:touchListener="#{0L}"
>
.
.
.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text"
android:background="#color/color_primary"/>
Since this is a constraint layout, you should put start, end and top constraints for proper results.
Example code:
<androidx.coordinatorlayout.widget.CoordinatorLayout(This layout is the )
android:layout_width="match_parent"
android:layout_height="match_parent"
app:touchListener="#{0L}"
>
.
.
.
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Some Text"
android:background="#color/color_primary"/>
Something like this in the proper format would work for you. Happy coding! :)

Android - Seemingly harmless layout causes app to crash after short use without any errors

After 2 days of fruitless testing, I've decided to post my issue here, in the hopes that I'm missing something obvious.
I've boiled down a seemingly innocuous xml-layout to a random collection of images, layouts, and a scrollview. Here it is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/wood_texture"
tools:context="com.testlayout.example.testlayout.MainActivity">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:src="#drawable/image_one"
android:id="#+id/imageOne"
android:adjustViewBounds="true"
android:layout_gravity="center_vertical"
android:visibility="visible"/>
<ImageView
android:layout_width="300dp"
android:layout_height="150dp"
android:background="#drawable/dark_wood_texture"
android:id="#+id/darkWood"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:visibility="visible"/>
<HorizontalScrollView
android:layout_width="300dp"
android:layout_height="150dp"
android:id="#+id/handScrollView"
android:scrollbars="none"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:visibility="visible">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/handLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/image_three"
android:id="#+id/imageView"
android:adjustViewBounds="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/image_three"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/image_three"
android:id="#+id/imageView6"
android:adjustViewBounds="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/imageTwo"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="#drawable/image_two_tiled"
android:scaleType="fitXY"/>
</RelativeLayout>
I can load this layout onto my phone just fine, but after swiping around in the scrollview for as little as 5 seconds, the app will suddenly crash to the home screen - without reporting that the app has stopped working. I've been testing on a Samsung Galaxy s6.
I've also tested this on a Samsung Galaxy Tab 2, where this problem does not occur (both my real app and this test app run just fine on the tablet).
I've created a new Android Studio project; the only changes I've made are to the res/layout/activity_main.xml, as outlined above. I've also included the drawables I'm using. I'm hoping someone with better debugging skills than I can either pull down that project, or simply create a new one of their own using the above layout (that's all there is to it, though you'll need my drawables regardless).
I'd like to clarify that I'm not looking for a way to fix this issue, I'm trying to understand the issue. The thing is, after 2 days of testing, I've found half a dozen ways to seemingly "fix" the issue. But none of them make any sense, and they all seem unrelated. If I don't know why my solution fixes the issue, I won't know how to avoid it during future development.
Observations
As I mentioned above, I've found several ways to "fix" the issue (i.e. make it no longer crash), but none of them seem to be related. Here are a few:
Set the visibility of almost any of the elements to gone.
Remove the background from the root element.
Remove the line android:tileMode="repeat" from drawable/image_two_tiled.xml
Note that changing the tileMode to something else - for instance, clamp - does not fix the issue. Only removing it (or setting it to disabled).
Set the src of the ImageView with the id "#+id/imageTwo" to image_two_smaller_tiled.
This is the exact same image as image_two_tiled, just a smaller resolution.
This is by no means an exhaustive list of, but it gives you an idea of how disjointed these fixes are (especially the tileMode one).
As near as I can tell, it looks like some kind of memory issue. I'm fairly new to android development, so I'm not quite familiar with the memory constraints I need to work with, but I would be horrifically concerned if I was causing the heap to explode with so few images, and of fairly small size (at the very least, certainly not big).
If anyone could tell me exactly what is causing my app to crash, I would be. . . Well, I would be extremely grateful. 'Cause after 2 days of trying to debug this myself, I'm about ready to quit android development : (
Edit
The app itself does not throw an exception, however logcat does consistently show this error at the time of the crash when I'm not filtering log messages from my app alone.
E/Resources: RunTimeException
android.content.res.Resources$NotFoundException: Resource ID #0x7f0202cf
at android.content.res.Resources.getValue(Resources.java:2558)
at android.content.res.Resources.startRC(Resources.java:1116)
at android.app.ActivityThread$mRunnable.run(ActivityThread.java:3056)
at java.lang.Thread.run(Thread.java:818)
e2: I'm starting to wonder if this is an issue with my phone, and not the app, since I can run it just fine on my tablet. I'd really like to know if anyone else is experiencing this issue if they try to run this on their Galaxy s6. Specifically the S6 - that would tell me if it's an issue with my phone or all S6's in general.
This previous SO post answer solved my issue.
In short, it was the BitmapDrawable that was causing the entire issue. While unfortunately I cannot say why this fixes the issue, setting the view that uses the bitmap with layerType="software" will prevent the crashes.
In a layout: android:layerType="software"
In code: view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

View too large to fit into drawing cache on Webview inside scrollview

I am working on a scrollview that contain a webview, it works perfect on the 2.3, 4.1 , but when I try it on the 4.4 emulator, it show
View too large to fit into drawing cache, needs 5744640 bytes, only 3932160 available
The webview is just blank.
And it is the layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="#+id/newsTitle"
android:textSize="18sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/last_update" />
<WebView
android:id="#+id/newsContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/last_update" />
<TextView
android:id="#+id/newsDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/last_update" />
</LinearLayout>
</ScrollView>
</LinearLayout>
I tried to use mywebView.setDrawingCacheEnabled(false); but it just return the same warning.
Also, I find the problem occur when the webpage is overscreen size , but when I show it , I find the layout of the web is slightly different, on 2.3 , 4.1 , it can simply start the new line if the word is exceed the page, however , in 4.4 it does not , so part of the word is out of the screen .
How to fix it? Thanks
My Suggestion is give layout height to webview so that it wont exceed the your specified height
<LinearLayout
android:id="#+id/webview1"
android:layout_width="fill_parent"
android:layout_height="150dip" >
<WebView
android:id="#+id/sampletxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
In your activity just include the below lines
SampleTxt.getSettings().setLoadWithOverviewMode(true);
SampleTxt.getSettings().setJavaScriptEnabled(true);
SampleTxt.loadData("Your Text To show the Webview",
"text/html; charset=UTF-8", null);
It will work fine. any doubts let me know
I suggest you to use your own WebView client. In android we can use WebViewClient or WebChromeClient. Using this you would get better result that you want. Just try it and check.
For WebViews in Android, you should start from the assumption that things are buggy. They shouldn't be, but as you discovered, if you make the background a flat color, it "resolves" the issue.
Having said that, it is still a good idea to keep in mind that you're dealing with a wide range of mobile devices with wildly different processing and memory allocations when you're coding for Android phones, so always be sure to test on a real device.
If you don't have at least 4 or 5 different physical Android devices that you can test on, then look around for services that allow you to use their devices to test remotely. Never believe that because you have tested something in an emulator, it will behave the same on a real device.

Implementing autocompletetextview next to ImageButton using 9patch in a RelativeLayout

I'm having trouble implementing a SearchBox with an ImageButton to the right using assets provided by a designer.
I'm not sure if the problem is because of the assets or my implementation.
It should look like this, and it does in hdpi phones.
But look how it looks like in xhdpi emulated phone
It was tested on real devices too. Every devices without hdpi looks like the second example.
This is my implementation:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#e9e9e9" >
<ImageButton
android:background="#drawable/home_btn_ubicacion"
android:src="#drawable/home_icono_ubicacion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:id="#+id/button"/>
<AutoCompleteTextView
android:layout_toLeftOf="#id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/home_input_buscar"
android:hint="Ciudad o Barrio"
android:layout_alignParentLeft="true"
/>
I'm not allowed to post images because of my reputation so I'm sharing the whole test project on github at:
github.com/ejmedina/SearchBoxTestProject
Again, it doesn't look like a link because of low rep.
Thank you all in advance as always.
The designer sent new assets which fixed the problem.
It seems he made the first ones with Photoshop and the patch didn't worked as intended.
I've pushed the new assets to my github repo and they will remain there for educational purpose.

Layout displayed in Emulator is not same as in real device

I am trying to display a text box using textView.I am adding some data in it during runtime. I just want it to display a box of size 23 lines.
Code am using is this.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/twittertext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadingEdge="vertical"
android:maxLines="23"
android:minLines="23"
android:background="#drawable/dropshadow"
android:scrollbars="vertical"
android:text="Getting data on your slow n/w..."
android:textColor="#ffffff"
/>
</ScrollView>
</LinearLayout>
Now when i see this in emulator it's coming perfectly (Android 2.2) but when i test the same code in a real device (Wildfire 2.2.1) the box is not coming for 23 lines. Rather it just show a 5 line box. Am able to scroll but looks like the
:minLine
is not working.
Please help me.
Ok. I dont have a answer for it. But this is how i solved, just in case someone else want it.
I have used the screen pixels and then calculated the pixels i need for the view. Then added the same as
android:layout_height
property and it worked for me.

Categories

Resources