ScrollView does not respond to keyboard - android

I have a problem with EditText scroll behaviour in ScrollViews, normally it scrolls up content inside scroll if keyboard opens over it. But if you fill the layout inside the scrollview dynamically, keyboard push up whole screen, anyone else had this problem before.
Thanks in advance.
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header_area" >
<LinearLayout
android:id="#+id/contentHolder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
This sample works normal, linear layout scrolls in scroll view but it shows scrolls even keyboard closed. I can not use fixed heights.
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:layout_below="#+id/header_area" >
<LinearLayout
android:id="#+id/contentHolder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
I have tried xml below, it works as expected on a new project but push up window in my project. I have found some other people having this problem, I'll share solution asap i found it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/header_area"
android:layout_width="match_parent"
android:layout_height="50dip" >
</RelativeLayout>
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/contentHolder"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

<application
android:icon="#drawable/is_logo_iphone"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
Problem is "Fullscreen" theme does not support resize. Using
android:theme="#android:style/Theme.Black.NoTitleBar"
solves the problem.
Thanks for answers.

That is because your scrollview is resizeable. Try to set the height of your scrollview to match_parent instead.
Try also setting android:fillViewport="true" inside your scrollview.
Also you wouldn't happen to have added something like following within your activity tag of your manifest: android:windowSoftInputMode="adjustResize" That would pretty much ruin all our effort. If you have following within the manifest remove it.
Your probably have to configure your manifest. Here is a list of possible configurations for soft keyboard. It might be android:windowSoftInputMode="adjustPan" you want to use.

Related

android scrollview not working windowSoftInputMode

I have one activity and in this activity's windowSoftInputMode is stateAlwaysHidden
android:windowSoftInputMode="stateAlwaysHidden"
i created custom Xml file and in this xml i have one edittext in top position and one button in bottom position
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:minHeight="#dimen/u_base_min_height">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:minHeight="#dimen/u_base_min_height"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/transfer_headerView_height">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:paddingLeft="#dimen/u_common_margin_left"
android:paddingRight="#dimen/u_common_margin_right">
<Button
android:id="#+id/u_done"
android:layout_width="fill_parent"
android:layout_height="#dimen/u_widget_height"
android:background="#drawable/rounded_corners_blue"
android:text="#string/u_register_next"
android:textColor="#ffffff"
android:textSize="#dimen/u_common_text_size" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/u_common_margin_left" />
</LinearLayout>
</RelativeLayout>
when keyboard is showing i can not show my button whitch is a bottom position,scrollview now working.
i searched about my problem and i tryed to change windowSoftInputMode in manifest file
android:windowSoftInputMode="adjustResize"
but i don't need this solution because my button moving keyboard up when my keyboard is showing...
how i can solve my problem? if anyone knows solution please help me
thanks everyone
put your bottom button outside the scrollview. Make two separate layouts. In upper layout put your scrollview content and in lower layout put your bottom button.
For that use below code
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true">

Android Webview with child at bottom

I've been searching both Google and stackoverflow for a while now and haven't found anything answering my question.
I'm wondering about putting a LinearLayout (with no specific known height in pixels) at the bottom of a WebView. This LinearLayout will later be populated with a fragment containing comments for the article displayed in the WebView.
The issue of the problem is that the WebView is almost always larger than the screen so the user has to scroll to read the full article. At the bottom of the scrolling I want the CommentsFragment to be inserted (through the LinearLayout, it takes a few parameters so it can't be loaded directly from the XML).
I've tried a bunch of solutions but all of them make the LinearLayout stick to the bottom of the layout the all time, not on the bottom of the WebView.
My current code is the following, of course not working:
<?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" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" />
<LinearLayout
android:id="#+id/comments_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Thank you for your help!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/comments_container"
android:layout_below="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
got it working after a few rounds. The solution was using a ScrollView then inside that a relativelayout mirroring #Karan_rana's answer.
If you want to put the comments fragment below web view then you can try as following and tell me if it works for you
<?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" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/comments_container"/>
<LinearLayout
android:id="#+id/comments_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Try this, make sure to have layout_height="wrap_content" in your WebView
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/comments_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

how to separate layout in android

I not really sure how to describe correctly my problem. My layout contains a top menu with linearlayout, and below it is a tablelayout that is wrapped with a scrollview. My problem is when I scroll up, the content tablelayout moves up and blocks the top menu view. So could anyone know how to solve the problem please point me. Thanks
This is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/menu_bar" >
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myTableLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="140dp"
android:stretchColumns="1" >
</TableLayout>
</ScrollView>
</RelativeLayout>
You have to set your ScrollView to be below your LinearLayout, else it stacks on it.
Hope this helps!

glsurfaceview inside a scrollview, moving but not clipping

I have a scrollview with a linear layout inside. One of the elements inside this linearlayout is a glsurfaceview.
This all works correctly and when I scroll the glsurfaceview moves up and down however when the glsurfaceview reaches the top or bottom of where it should of the scrollview where it should be clipped it is not and is continued outside of the scrollview. This screenshot should make it clearer:
Don't think it's completly nessecary but here is my layout.xml:
<?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="wrap_content"
android:orientation="vertical"
android:padding="6dip"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
>
<!-- LOTS OF SEEKBARS/TEXTVIEWS -->
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.4"
android:layout_marginRight="10dip"
android:layout_marginLeft="10dip"
android:orientation="horizontal" >
<android.opengl.GLSurfaceView android:id="#+id/glview"
android:layout_width="100px"
android:layout_height="250px"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_marginTop="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<!-- OK/CANCEL BUTTONS -->
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
All help much appreciated :)
Hosting SurfaceViews inside ScrollView (or Listview, etc.) is currently not supported.
You may use below lines for removing over scrolling :
glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
glView.setZOrderOnTop(true);
glView.setZOrderMediaOverlay(true);
And for removing black background :
linearLayout.setBackgroundColor(context.getResources().getColor(R.color.white));
linearLayout.addView(glView);
Also add below line in your manifests file :
android:hardwareAccelerated="true"
It is not about support as answered abowe. The cause of issue is that GLSurfaceView is not on the view level. In short: for you case you have GLSurfaceView at the first level, then other views with holes in views abowe GLSurfaceView (this handles by windows manager, and it dosent matter where you put GLSurfaceView on xml, it will be on first level in any case and others views on next level)
So, what you need is to force view update, and there is work around: you should put scroll with GLSurfaceView or (RecyclerView with GLSurfaceViews) "between" two FrameLayouts. something like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
---- here should be linear layout with your glView, or RecyclerView instead if required ----
</ScrollView>
--- this frame also required: ---
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
</FrameLayout>

Android: EditText on top of WebView?

I would like to imitate the behavior of the default android browser - The EditText (the address bar) on top will start to "disappear" once the user scrolls down. The only thing I can think of right now is to put the EditText and the WebView in a ScrollView but that would create other problems, and is not recommended.
What do you think?
Create a custom View by extending WebView and override onScrollChanged(). With a little calculations you can accomplish your task.
What problems does your ScrollView cause? This one should work fine:
<?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:stretchColumns="0" android:orientation="vertical">
<ScrollView android:layout_width="fill_parent" android:layout_gravity="top" android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0" android:orientation="vertical">
<EditText android:layout_width="fill_parent" android:id="#+id/editText1" android:text="yourtexthere" android:layout_gravity="bottom" android:layout_height="wrap_content">
</EditText>
<WebView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/myWebView"></WebView>
</LinearLayout>
</ScrollView>
</LinearLayout>

Categories

Resources