Android: Webview does not resize on rotation (ICS) - android

I have a simple WebView in my layout, with the following setup
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/baserepeat"
android:gravity="top|center_horizontal"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/productDetailContentWebview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#drawable/baserepeat" />
//other items...
Inside my manifest I have the containing activity set to
<activity
android:name=".Products.ProductDetailActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="sensor"
android:theme="#style/Theme.CPS" >
</activity>
My Webview is populated with a simple HTML file on the device, which works nicely. The problem is that when I rotate the device from portrait to landscale, the webview becomes a good deal taller, pushing whatever was below it further down in my layout. The amount of content doesn't change - it is all set in OnCreate().
I'm using the Webview to render the content with it's own special stylesheet, and it must stay within the ScrollView.
I can provide more information if required :)

I had the similar issue when working on 2.3/4.0...
I tried several things but the solution which helped me in getting rid of the core issue was:
removing screenSize from android:configChanges in AndroidManifest.xml
Hope it helps !!!

Try including your webview inside a FrameLayout.
<LinearLayout>
<FrameLayout>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/productDetailContentWebview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#drawable/baserepeat" />
</FrameLayout>

Related

How to make a WhatsApp like `RecyclerView`?

This may be possible of duplicate question i have tried all things none of it works i need to make whatsapp like chat model using RecyclerView and at the bottom EditText and a Button bottom my problem is i can have EditText and bottom at the bottom but i need scroll to view that EditText and Button, what i should have when user enter that page EditText and Buttonb should appear without scrolling and one more problem there is lots of space between two items in thatRecyclerView` how to reduce that space let me post what i did so far:
My Recyclerview ChatLayout:
<?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.support.v7.widget.RecyclerView
android:id="#+id/constraint_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="4">
<EditText
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter Message"
android:lines="1" />
<Button
android:id="#+id/btn_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Send" />
</LinearLayout>
</RelativeLayout>
How to do this as am new for android development someone please help me!
You should change the android:height in layout that u use in your RecyclerViewAdapter to wrap_content
And also in your manifest
<activity
...
android:windowSoftInputMode="adjustPan"
...
></activity>
Their are many libraries out there.This library is a sample Android App which can be used as a starter application for a chat application.You can take reference or implemented this library in your project
check your row item(layout xml file) which is used in your viewholder. I think you have used match_parent in your parent view. Make it as wrap_content.
For that scrolling issue, check your code for smoothScrollToPosition(int). may be you have used this method in your code.

Android soft keyboard hides controls

I know there are lots of questions about this but none of the answers are working for me. Here's a screen in question before opening the keyboard.
Here's the screen after opening the keyboard by tapping on an EditText, and then scrolling as far down as possible.
Note that besides the final edit control being mostly concealed, all the text and the button after it are inaccessible.
Here's the fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:validator="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment"
android:background="#color/background">
<TextView android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/primary"
android:text="#string/help_header"
android:textSize="20sp"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
/>
<TextView android:id="#+id/drop"
android:layout_below="#id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/help_sub_header"
android:textSize="16sp"
android:textColor="#color/material_drawer_secondary_text"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginBottom="#dimen/activity_vertical_margin"
/>
<View android:id="#+id/divider1"
android:layout_below="#id/drop"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_gray_background"
android:layout_marginBottom="#dimen/activity_vertical_margin"/>
<LinearLayout android:id="#+id/linear1"
android:layout_below="#id/divider1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin">
<!-- Several EditTexts and such -->
</LinearLayout>
</RelativeLayout>
</ScrollView>
It was originally in a LinearLayout and I changed it to a RelativeLayout based on a suggestion, but that didn't change anything. I have also played with the layout height (wrap_content / match_parent) of the top two levels of view groups to no effect. Here is the activity declaration in the manifest:
<activity
android:name=".MainActivity"
android:label="#string/application_name"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
I've also tried adjustPan and it doesn't seem to change. I'm not too concerned about what exactly the UI elements do when the keyboard opens, I just want the whole layout to be accessible by scrolling.
Basically everyone points to the soft input mode, but that doesn't seem to be doing anything. Is there something about fragments that I'm missing? Or maybe this is harder than I'm expecting and I need to make a custom layout class and measure the layout and nasty stuff like that? I can add the activity layout though there's not much to it, or code such as the fragment creation/transaction stuff.
THat's what the keyboard does. It covers the bottom of the screen. If you want it to not cover your app at all, you can use adjustResize. That will scale your app to only draw in the top half. But if your content is too big it still won't fit and it will look as if your app is covered (even though it isn't. Scrolling it via a scroll view should work then (although I've never actually tried it). But the only thing you can do to control the behavior when the keyboard is up is the softInputMode.
If you have lots of adjustable space or whitespace, there are techniques that will shrink you somewhat and may allow your full app to appear in the reduced space. This isn't the case here, you have too much stuff on screen (except for maybe on a tablet in portrait mode). So they aren't going to apply here.
It turns out the problem was with a library, material-drawer (nice library). For anyone else encountering this:
https://github.com/mikepenz/MaterialDrawer/blob/master/README.md#i-have-problems-with-the-softkeyboard-how-can-i-fix-this
Call Drawer.keyboardSupportEnabled(this,true) and the layout will arrange and scroll appropriately.

Softkeyboard hides elements of my layout that I want to be visibles

I've got a layout that looks like first image and when I open the softkeyboard looks like the second image, but I want it how it seems on third image:
I read a lot about adjustpan and adjustresize on the manifest but nothing works, the xml structure is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blanco"
android:gravity="top"
android:orientation="vertical"
android:weightSum="10" >
<!-- LOGO -->
<LinearLayout
android:id="#+id/logo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3.7"
android:background="#color/green_logo"
android:orientation="vertical"
android:gravity="center"
android:paddingTop="65dp" >
<ImageView
android:id="#+id/logo_registro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/logo_registro" />
</LinearLayout>
<FrameLayout
android:id="#+id/contentFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6.3" >
</FrameLayout>
</LinearLayout>
First part is the green part with the app logo and inside the FrameLayout I put Fragments that contains simple LinearLayouts or RelativeLayouts with parts of my Login forms.
Put this on your Manifest, inside the activity
<activity android:name=".YourActivity"
android:configChanges="keyboard|keyboardHidden"></activity>
Set your windowSoftInputMode in your manifest for this activity to be adjustResize. THere are 3 possible settings for this- nothing, resize (shrinks your app to fit the remaining space), and pan (scrolls your app so the focused field remains on screen).
Just Add the empty scrollview and it will work
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>

How to show a WebView with Theme.Dialog style in Android

I declared a WebView activity in the manifest like this:
<activity android:name=".MyWebView"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.Dialog">
</activity>
The WebView looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
When I start this activity within my main activity, only the title of the dialog, containing the apps name, is visible but not the WebView. If I add a TextView to the LinearLayout, it is shown as well, but still the WebView is missing.
If I don't apply android:theme="#android:style/Theme.Dialog" in the manifest, the WebView is displayed.
Why is that and how can I show a WebView in a dialog?
I found that it works if you change the webview to wrap_content rather than fill_parent. No idea why. It's probably a bug.
The best way I have found is a little trick like this:
Notice the 1000dp for minWidth and minHeight
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="1000dp"
android:minHeight="1000dp" >
<WebView android:id="#+id/web_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
The other way is to wrap content on the WebView but it wont expand until you load a webpage..so it will start small, then expand. This hackish way will make the large dialog at start.
I would think what you are doing would work. Maybe try to override the dialog class instead of the activity class.
Use the WebView as the root layout - without any surrounding element.
Don't know why it didn't work with the surrounding layout.

html textfield in WebView in an Android application is hidden by the soft keyboard

I have an Android application that is a TabHost with a WebView. I use it to load a specific html file that has a text field in its bottom part.
When I touch the html textfield, the soft keyboard pops up, and hides the textfield, so that I cannot see what I have typed.
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:focusableInTouchMode="false"
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="63dp" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
I have tried to configure the AndroidManifest.xml file with android:windowSoftInputMode="adjustResize" with no success. I have also tried replacing the FrameLayout in my layout with ScollView, but that caused my webview to increase in size indefinitely when the application is running.. this may be due to some javascript I have running on the page.
I have noticed that the android's web browser has a nifty behavior - in a web page, after the soft keyboard pops up, the web page scrolls smoothly so that the focusable textfield is visible to the user. How can I have this kind of behavior in my application?
I was getting crazy nothing works android:windowSoftInputMode="adjustResize" may help but be sure to have your app not in full screen.
Removing full screen for my app solved the problem with the layout resize with softkeyboard.
<item name="android:windowFullscreen">false</item>
I found a solution for this issue. (about a week after I posted the question; I only got to answering in stackoverflow today...)
I had pieces in my code that changed the WebView's height (to have room for a TabBar). Turns out that when you invoke setLayoutParams on a WebView, it will no longer change its height even if you have android:windowSoftInputMode="adjustResize" set.
I circumvented the need to change the WebView's height by adding the TabBar to the main.xml layout file, with an initial size of 0. When I increase the TabBar's size, the WebView's size decreases automatically, and it preserves the android:windowSoftInputMode="adjustResize" behavior.

Categories

Resources