ScrollView does not work, I have a layout with some components like EditText, and when I'm typing something EditText keyboard rises, and along the component, however it appears above the other, the ScrollView does not respond to their function.
Already googled, and found some similar problems, but none solved my problem.
Below my layout.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<TextView
android:id="#+id/txtDescricaoDocumento"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/edtDescricaoDocumento"
android:layout_alignBottom="#+id/edtDescricaoDocumento"
android:gravity="right"
android:text="Descrição:"
android:textAppearance="?android:attr/textAppearanceMedium" />
...
And my manifest.xml
<activity
android:name=".LancarDocumentoAcaoActivity"
android:windowSoftInputMode="adjustResize" >
</activity>
Couple things I've tried this without the relative layout inside of the scroll view...and scroll view worked perfectly.
1.Is relative layout necessary inside a linear layout? Try removing it if not.
2.Is the attribute WindowSoftInputMode necessary for the corresponding class if not you will have the soft keyboard covering view elements like it is mentioned.
Let me know if this works.
Related
I have this strange "bug". A button that change its backgroundcolor inside a scrollview cause the scrollview to scroll up.
Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/img_loading" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:id="#+id/txt_read_story_title" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:id="#+id/txt_read_story_author"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:id="#+id/txt_read_story_content"
/>
<include layout="#layout/inc_reactions_buttons" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
Inside the inc_reactions_buttons.xml layout there are six buttons in an horizontal linearlayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal">
<ImageView
android:id="#+id/btn_funny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_reaction_funny" />
...
</LinearLayout>
In the OnClickListener of this buttons, I change the enabled and the backgroundColor of them
mBtnLove.setEnabled(false);
mBtnLove.setBackground(Color.parseColor("#FF000000"))
The problem is that when a button is clicked, the scrollView scroll to the top.
If I remove the setBackground, the scroll doesn't happens.
I've already tried to use other types of view (ImageView, ImageButton) but the result is the same.
Happens on API 25 and 26 (didn't test on earlier version)
Anyone knows the reason?
Thanks
Ok, found a solution.
As I stated in a comment above, the problem is caused by the TextViews having the attribute "textIsSelectable" set to True. It is not clear the reason (something calling the requestChildFocus), but I've found a workaround. In my buttons code, I set the textIsSelectable attribute to false, then change the backgroundColor of buttons, then reset the textIsSelectable to true.
Anyone have a better option?
Had same problem. In my case, simply setting
setKeyListener(null);
setFocusable(false);
for each EditText inside my ScrollView, fixed it.
Setting textIsSelectable to false is a solution too.
i want the whole layout move up to show while popping the soft keyboard, but the button on the bottom of the view cannot be seen.
the AndroidManifest.xml:
<activity
android:name="cn.duckr.android.plan.PlanConfirmPaymentActivity"
android:windowSoftInputMode="adjustPan"
style="#style/base_activity_style"
android:theme="#style/confirm_payment_anim_theme" />
To ensure that the system resizes your layout to the available space—which ensures that all of your layout content is accessible (even though it probably requires scrolling)—use "adjustResize".
link
android:windowSoftInputMode="adjustResize"
You can put whole layout except the particular button in a ScrollView to achieve this.
like 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"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView5"
android:fillViewport="true">
//put your contents here..
</ScrollView>
<ImageButton
android:id="#+id/ibSample"
android:layout_width="50dp"
android:layout_height="50dp"
android:adjustViewBounds="true"/>
</RelativeLayout>
I'm creating an Android application which requires a (1) static 40px tall Container (linear layout at the moment), (2) a scrollable-dynamically loaded content layout (ScrollView wrapped LinearLayout at the moment), (3) and an entry/answer field.
The Idea is (2) the scrollable-dynamically loaded content should be resized so that no matter what the (1) answer field and (3) container are visible. Also, I need every bit of content-within the dynamically loaded portion-able to be viewed.
The problem is that when the soft keyboard is shown I am getting a pan upward which hides the 40px container as well as a portion of my scrollable region (I can scroll all the way up and indeed the top few lines of my scrollable portion cannot be reached).
The activities entry in manifest:
<activity
android:name="com.xxxxx.xxxxx.xxxxxx.paid.activities.GamePlayActivity"
android:windowSoftInputMode="stateAlwaysVisible|adjustResize"
android:label="#string/app_name" >
</activity>
The layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/game_play_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/activity_home_screen">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40sp"
android:background="#FF000000"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/game_play_table"/>
</ScrollView>
<EditText
android:id="#+id/game_play_answer"
android:layout_width="match_parent"
android:layout_height="40sp"
android:layout_margin="3sp"
android:inputType="textAutoComplete"/>
</LinearLayout>
Any ideas would be greatly appreciated-I've been searching and trying different implementations found on stackoverflow however I have not met my requirement yet.
My Android app's main activity looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical"
android:paddingLeft="60dp"
android:paddingTop="53dp" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/billAmountText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/billAmount_string"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/billAmount"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_below="#id/billAmountText"
android:layout_marginTop="3dp"
android:inputType="numberDecimal" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
In order to make sure the background image (defined in the first RelativeLayout) does not get squeezed when the keyboard pops up, I have set android:windowSoftInputMode="stateVisible|adjustPan in the manifest file for my activity. All good with the background and layout now, nothing gets resized.
But the problem is that my ScrollView doesn't work now because I suppose the system thinks the window doesn't need resizing due to my above modification to the manifest - so the ScrollView is not activated. The opposite happens when I take android:windowSoftInputMode="stateVisible|adjustPan out, the scrolling works, but the background gets squeezed when the keyboard pops out.
Is there any way to code it so that my background doesn't get squeezed, and my ScrollView still works? Thanks!
Try to use in your activity the property windowSoftInputMode with the following values:
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
I don't know if it's necessary but you can try to add to your layout's ScrollView tag the fillViewPort to true.
So it should look like something I show you below:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<!-- Other Views -->
</ScrollView>
Let me know about your progress.
In your scrollview put a relative layout, child 0 is an imageview, and child 1 is your content. Use the imageview for your background image (src) rather than the background of the scrollview. The imageview will respect scaleTypes, whereas the background of a layout will not.
My layout looks like this:
<RelativeLayout>
<RelativeLayout>
</RelativeLayout>
<ViewFlipper>
<ScrollView>
<LinearLayout>
<EditText />
</LinearLayout>
</ScrollView>
</ViewFlipper>
<RelativeLayout>
</RelativeLayout>
</RelativeLayout>
When focused on the EditText in the middle, the soft keyboard pops up as expected, However it always resizes the layout even though I have android:windowSoftInputMode="adjustPan" in the manifest.
The problem with resizing is that only the ScrollView shrinks, leaving the RelativeLayouts above and below it intact, which can almost completely obscure the EditText.
I've tried hiding the RelativeLayouts when the keyboard is shown (that's another sad story), but adjustPan sounds more suitable. However it has no effect on this activity.
How can I force adjustPan to work despite the presence of the ScrollView?
Update:
SO won't let me answer my own question, but the solution is setting android:isScrollContainer="false" on the ScrollView.
Good question mostly Developers do the same thing but this is not a correct way you have need to do. This will help you.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ViewFlipper>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText />
</LinearLayout>
</ScrollView>
</ViewFlipper>
<LinearLayout>
You should take LinearLayout with orientation as Vertical or horizontal view where you have never adjustment problem created.this is very simple.
try this in your manifest's the activity tag:
android:windowSoftInputMode="stateVisible|adjustPan"