I have the following problem, and I cannot figure out how to eve try solving it (or whether there is a way):
My problem
I have SrollView, containing to EditText input fields. One is a single line, below is a multiline. Everything's fine and works as expected, up until I put too much stuff into the multiline EditText. When I fast scroll the view, the scrolling skips and stutters, very obviously, the whole effect is rather disturbing. tried on a Galaxy S3 with a custom AOSP ROM, and Note 4 with official 5.1.1, no difference at all.
I would expect a very heavy EditText makes it difficult to smoothly redraw on a fling, but this starts happening with relatively short text (approx 4-5 screen-pages long).
Edit: This also seems to happen on a simple scroll, when I do as much as touch it and move it a few lines (scrolling is not near to being smooth, that is)
The setup
I have reduced the widgets to the bare minimum, even removed padding, only the problem does not improve. From the Java code I also removed anything (any styling, or typeface, anything that affects the widgets at all), still no improvement.
If this is of any significance, the ScrollView in question is inside a fragment, that is one of two pages of a ViewPager. There is nothing else on this fragment ATM.
Here's the XML (as you will see, it's as base as possible):
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false"
android:inputType="textMultiLine"/>
</LinearLayout>
</ScrollView>
What I tried
Any advice I found regards only ListViews, and some attributes like android:smoothScrollbar, which have no effect here (I tried them all).
For the record, I did try out of frustration all of the below ( I know most of these has not much to do with ScrollViews, but I'm becoming hopeless here):
android:hardwareAccelerated="true"
android:fastScrollEnabled="true"
android:scrollingCache="true"
android:smoothScrollbar="true"
and also tried setting from the Java code things like
.setSmoothScrollingEnabled(true);
.fling(3500);
still no luck.
Question recap
Is there any way to make a simple widget like this scroll smoothly at all?
Thanks for your time if you've read through and even more if you answer. :)
Related
I'm trying to make an app (well, part of an app) which takes an input string from the user and displays it fullscreen, in a different fragment. Which I've got working, but using autoSize on it makes the text so big it gets wrapped, like this:
Not all words get broken if they're small enough:
Looking through the docs (and some web searching), these were the only XML attributes that seemed relevant:
android:breakStrategy="simple"
android:ellipsize="none"
android:hyphenationFrequency="none"
None of them seemed to change the behaviour. About the only thing I could find that makes a difference is android:singleLine="true" but that makes things worse:
and I'm not sure I want to know how much worse that makes it when there's multiple words.
I've pared the fragment layout down to basically the minimum possible that I can think of:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<TextView
android:id="#+id/frag_big_text_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/big_text_background"
android:gravity="center"
android:keepScreenOn="true"
android:clickable="true"
android:longClickable="true"
android:focusable="true"
android:textColor="#color/big_text_foreground"
android:breakStrategy="simple"
android:ellipsize="none"
android:hyphenationFrequency="none"
app:autoSizeTextType="uniform"
app:autoSizeMaxTextSize="240sp"
app:autoSizeMinTextSize="14sp"
app:autoSizeStepGranularity="1px"
tools:gravity="center"
tools:targetApi="m"
tools:text="BIG TEXT HERE"/>
</FrameLayout>
I know I could set the autoSizeMaxTestSize to something lower that should fit most phone screens, but then it won't fill the screen on a tablet (and don't worry about targeting m, my AVD is set to match the specs of my phone, which is on API 29). The code that sets the current text is also pretty simple:bigTextView.text = messageList[index] (and it's definitely not a problem with the list it's pulling from, since I tried hard coding it with bigTextView.text = "thisisareallylongword", same result).
I'm hoping this is one case where I'm missing something obvious and don't have to reinvent the wheel. Wheels aren't my area of expertise, I figured that out when I had to fix a broken pip install.
But whatever reinvention or stupid intervention is required, can anyone help me out?
I am using a simple Linear-Layout with lots of different views and a grid-view. But my problem is that I don't want my grid to be scrollable. I have enough space, at least in my phone and I am also using scroll-view. I just want my grid to not be scrollable, even if it makes my activity too much scrollable.
I can't post whole of my activity because it's too large. So, I am posting only the grid.
If you want anything else, feel free to ask for, I will post that also
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/gridview_info"
android:layout_gravity="center_horizontal"
android:numColumns="3"
android:nestedScrollingEnabled="false"
android:layout_weight="1" />
Pls expect late reply.. I am going to sleep and will go to school tomorrow. Will reply only after 6pm (Indian Standard Time)
Thanks in Advance
Change your Gridview property android:layout_height="wrap_content"
Is it possible to hide this in XML file:
myactivity.xml has more than 80 views, bad for performance ?
I have a complicated UI. So, I want to hide this warning. I mean no way to switch UI into ListView, etc.
I think the issue here is the layering. If it has to layer 80 views on top of one another, that is really bad. Otherwise, that is a LOT to manage
You can see just how bad your UI performance is by using the Android tools in Developer Options > Debug GPU overdraw (on) and Show Surface updates to On. That will show you the performance issues.
Now to fix them, custom view XML'scontaining your subviews are the way to go.
Code maintainability is really important here. Right now a single one line change can screw up everything whereas with custom loaded subviews you minimize this greatly and ask a bit less of the OS at the onset potentially.
You can hide/ignore it by adding tools:ignore="TooManyViews" to the view that is making that error. For example:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
...
</LinearLayout>
will be
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="TooManyViews">
...
</LinearLayout>
Note that this just hides the Lint warning and doesn't do anything else.
I'm not looking for code, either I won't post any, just an explanation, because I'm kind of lost.
There is this main issue about the resizing when softkeyboard appear.
In my case
I have a listView feeded with 2 editText and many textView with database content using a custom cursorAdapter.
1) AdjustPan
It's pretty simple. When I use the adjustPan property, everything works quite good, except the fact that when I press an editText in my listView and if the listview is bigger than the screensize, I can't scroll. This is actually the normal behaviour and I can understand it.
2) AdjustResize
Here I can scroll as much as I wish.
This property is the one I want to use. But I'm facing 2 issues :
When I press on one of the two editText, I just can't write in. Impossible, even thought it has the focus. I'm forcing the softkeyboard to appear, I try to type some letters in (remember that this editText is focused) but nothing happens.
Again, when I press one of the two editText, it just reorganize (apparently randomly) listview's items. Even thought it's working perfectly with adjustPan, with adjustResize, it's messing with items of the listView.
Any information about one of the 2 issues would be helpful. You can even ask for code, but one more time, I'm just looking for a general explanation that could help. Thanks.
Here this mention issue is same facing me in my app and here some change in my code is this working fine in my app. please try this...
<activity android:name="com.MainActivity"
android:configChanges="orientation|screenSize"/>
<ListView
android:id="#+id/fields_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:focusableInTouchMode="true"
android:focusable="true"
/>
<EditText
android:id="#+id/input_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="true"
android:gravity="top"
android:inputType="none"
android:textColor="#color/black"/>
The first time i focus an edittext view i notice a lag of one or two seconds before i can write anything in the textbox.
I notice this behavior even on an app without any code more than what's nessecary to initialize the application.
What am i doing wrong?
I've INSTANTLY fixed this issue for me; I saw in the DDMS that a lot of redraw's and recalculations were occurring while entering text, and a lot of info about RelativeLayouts were being called. So, I checked my layout; i had some Multi-Line EditText's who were direct children of a RelativeLayout. So, I wrapped those up into a Linear Layout, and specified my desired width/height at the LinearLayout, not each EditText.
Guess what? It totally fixed it!!
(below, some code... keep in mind, this is just an approximation. Don't try and copy/paste)
BEFORE:
<RelativeLayout>
<EditText
android:layout_width="wrap_content" />
<EditText
android:layout_width="wrap_content" />
</RelativeLayout>
AFTER:
<RelativeLayout>
<LinearLayout
android:layout_width="wrap_content" >
<EditText
android:layout_width="fill_parent" />
<EditText
android:layout_width="fill_parent" />
</LinearLayout>
</RelativeLayout>
Wrapped my EditText's into a LinearLayout, and relinquished dynamic layout controls to the LinearLayout.
It was an amazing and instant improvement.
Are you using the emulator?
This is common when you are using the emulator regardless of debug mode or not...at least from my (limited) experience so far. Try your app out on a real phone and see what happens.
I turned off USB debugging and uninstalled a few keyboards. Seems to work fine now. Thanks all.
Edit AndroidManifest:
My old code
< uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />
My new code
< uses-sdk android:minSdkVersion="8" />
I just removed the targetSdkVersion and the lag went away.
In my case the symptoms were the same, a delay occurred to present the keyboard and when typing the letters were gradually appearing.
The solution is because I had put a Background image in the RelativeLayout, when I did a test taking the background worked out and stopped the delay, so I entered an online site that reduces photos and then reduced from 93kb to 50kb and worked perfectly.
In my case the problem was the background-drawable for the activity (as dialog) on XML, it was too heavy. changing it, works fine.
In my case, the lag was because of the heavy serialised objects I used to pass in Intent putExtra() of activities in the app. Those would continue to stay in the memory and cause the problem.