Webview scrolling on Android not working properly - android

In the webview.xml, I only have a frame layout as a wrapper for the webView as the following,
<FrameLayout
android:id="#+id/scroll_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
As a little background of the webview, it's basically a mobile web page that displays pictures, and allows for horizontal scrolling(either swiping or clicking the 'next' button). Right now, I'm able to scroll to the next photo via swiping, but once I release my finger, the photo pops back to the original photo. Same thing is happening for clicking next, the screen displays half of the next photo before scrolling back to the previous photo.
I have absolutely no idea why this is happening as I've tried all options with playing with the horizontal scrolling attributes, but it still isn't working. Could anyone who has experienced this provide some insights. Please feel free to let me know what additional info you need.

try using linear layout rather than using frame layout as you have only one child that is webview for the parent layout.
this one works for me :
<?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">
<WebView
android:id="#+id/webview_content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

Related

Black box in screen after pressing Android menu button

I am creating a library class in Android Studio for my internship. I have created a custom RelativeLayout that inflates the layout shown below.
I can't find this issue anywhere, so I hope someone is able to help me out.
I have a layout file that looks like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/videoFrame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="#color/wallet_holo_blue_light">
<VideoView
android:id="#+id/videoBackground"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#null"/>
</FrameLayout>
</RelativeLayout>
I do need the FrameLayout, to be able to scale the VideoView where the VideoView's width is bigger then the parent this Layout is inflated into. I resize this VideoView dynamically on runtime-level, but that all works fine.
When I start the activity with this VideoView, everything is fine.
Whenever I hit the Android "Windows"-button and return to the Activity, a black box appears.
Screenshots
It also happens in Portrait mode. Then the black box is even bigger than half the screen.
After changing screenOrientation, so rotating my tablet, for example, the black box is gone again.
I really have no clue, does anyone know what the problem might be?

Best way to create a header and footer for webview in Android

I want to create news like activity that has title and date and some share and favorite buttons in the beginning at the top, the article text (and maybe some images and headers titles) is in html that I get from server, and at the end a list of related news!
I have to use WebView for the article html, but since I need the header and the main webview to scroll together, I may have to use them in the in wraping ScrollView, which, apparently is not the best option!
I have red these:
webview in scrollview and
Disable scrolling in webview
but I want to know what is the best way to implement this as of 2015! that can work with android 4.01+
Well, as it turns out, best way to do yet is to just put them in a scrollView !
It worked on my Samsung android 4.4, but I don't know about the rest !
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/news_activity_title_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//Some Widgets Here for header
</RelativeLayout>
<WebView
android:layout_below="#+id/news_activity_title_lay"
android:id="#+id/news_activity_web_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
</WebView>
<LinearLayout
android:id="#+id/news_activity_related_base_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/news_activity_web_view">
//Some Widgets Here foe footer
</LinearLayout>
</RelativeLayout>
funny thing, though is Android Studio is saying I should not do this ! :/

Overlay view like YouTube app

I am creating an app which does some tracking on a map. The tracking part works great inside my activity.
However, I want to have some kind of small overlay in the bottom right corner (like the minimalised video playback in the YouTube app) that stays there, even when I switch activities.
I have looked at this, but it's not really what I need. I don't need it to be moveable, and I think this is impossible to keep when switching activities.
Is there some kind of class that I can implement (Widget, Fragment, ...) that would fit my needs?
Thank you,
DebboR
This is a bit late and probably not relevant to you anymore, but maybe somebody else will find this helpful.
I don't think it's possible to switch activities and keep a certain view on screen. How I think this should be done is have a main activity with fragments that swap and in the activity's layout have a view overlay on top of the fragments container.
For example:
<?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"
tools:context=".MainActivity">
<!-- Container for the fragments -->
<FrameLayout
android:id="#+id/fragment_container"
android:layout_below="#id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- This view will overlay the fragment in the bottom right corner -->
<View
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>

Android: Allow scrolling form with adjustPan

I'm working on an Android app with a slightly complex layout and I'm having nightmares to make it work the way I want.
My main layout is defined like this:
<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="#000000"
tools:context=".MainLayout" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="none" />
<LinearLayout
android:id="#+id/menudown"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
... buttons ...
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true" >
... header content ...
</LinearLayout>
</RelativeLayout>
The idea of the layout is having a content frame(content), a footer menu (menudown) and a header (header) hovering over the content, aligned to the top of the screen. - Sorry guys, no image, confidential project.
The content is inflated with other layouts, depending on the section the user is, and some of them are forms to be filled. So, i just used the adjustPan and everything worked fine.
The problem here is: the client asked me to make the content scrollable while there's a soft keyboard showing, so that the user can view whatever he wrote on the other fields.
And it's painful because: the form fits the screen, so using content as a scrollview won't help, unless it gets resized.
And simply changing to adjustResize does not work because: the menudown goes up with the soft keyboard, which should not heappen. Also, the visual effect is terrible.
The app was already made for iPad (by someone else), and what heappens there is: the menudown remains aligned to the bottom of the screen, under the soft keyboard, which pushes only the content view up. Then, the content becomes scrollable, so that the user is able to see it entirely.
I have this same issue too, making keyboard behave the same way as it does on iOS. The best thing I can get from all the other posts is manually detecting the soft keyboard and moving the view up the difference.
This seems to be the best: How to check visibility of software keyboard in Android?

Android: problem scrolling my activity including a WebView

I included a WebView in my activity and load some Javascript in it which is then going to get data from an external website.
This works and displays fine but the problem is that my activity doesn't scroll when the WebView is done loading so I can't see the bottom of the WebView such as all the other Views I put below this. Any idea of how I should handle this?
Cheers.
Are you using scrollview in your layout? Try that and see if that helps.
Here is a link to the developer page
This works and displays fine but the problem is that my activity doesn't scroll when the WebView is done loading so I can't see the bottom of the WebView such as all the other Views I put below this.
You need to change your layout such that the "other Views I put below this" will be on the screen, and the WebView simply takes up the remaining space.
For example, here is a layout showing a WebView with a Button:
<?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/webkit"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
/>
<Button android:id="#+id/helpcast"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="View Helpcast"
/>
</LinearLayout>
Because the WebView is set up with a 0px height but a weight of 1, and because the Button specifies no weight, the WebView will fill all space left over after the Button is on-screen. The WebView content will scroll inside the WebView itself, if needed, based upon whatever Web page you load in there.

Categories

Resources