I'm doing an inadvisable thing here, and I know it, but I have a webview nested in a horizontalscrollview. (I needed more scrolling control than webview provides.)
The layout looks like this:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webRel"
android:layout_below="#+id/titlebar"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webZ"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</HorizontalScrollView>
And the results are as follows:
The webview isn't filling up the horizontalscrollview. The horizontalscrollview is filing the view, so I guess I could say the webview isn't filling the view even though I have both set to fill_parent. I would really, really like it if someone would help me figure out how to have the webview fill up the horizontalscrollview widthwise... because then I measure the height and use that measurement to paginate the text (which is then displayed in chunks widthwise which is why I chose horizontalscrollview.)
:D
(Alternatively, suggestions for a cleaner way to have smooth horizontal scrolling in a webview would also be helpful.)
The answer is: use android:fillViewPort. It'll have the contents of the scrollview stretch to fill the view.
WebView already supports horizontal scrolling, you should not put it inside a HorizontalScrollView.
Related
I'm struggeling to put a self-made view (size 3000px * 750 px) into any scrollView programmatically.
Information to my custom view: It simply extends View and there are just some drawing in OnDraw(), nothing special.
In order to gather all information for the drawing, this CustomView should be added, once a AsyncTask has loaded all information.
My problem is, that when I added my view programmatically to any ViewGroup containing a ScrollView or HorizontalScrollview, there is no Scrolling.
I've tried several layouts, for example this one:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_marginTop="50dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="#+id/linLayoutScroll">
</LinearLayout>
</HorizontalScrollView>
And once the AsynTask is finished:
LinearLayout linLayout = (LinearLayout)rootView.findViewById(R.id.linLayoutScroll);
linLayout.addView(new MyChartView(getActivity(), chartBuilder, ChartBuilder.DATASET.SPEED));*/
I tried to add my view to the LinearLayout, but often my View does not appear on screen at all or there is no scroling option and my view gets cut off at the end of display.
I guess there must be some magic trick to tell the scrollView to recheck its content and to decide whether there has to be a scrolling option or not. Can anyone help me out?
The error was inside my customView. I didn't set the Width and Height of my view (setWidth(), setHeight()). So the view did not know how big it really is. :-(
Sorry for wasting your time!
I want to scroll the background in android. I have a scrollview which has many views. I need to implement a way wherein i need to scroll only the background while adding the views. I came across many forums but none of them are very clear. Please give an idea or references to implement it. To give more idea for what i am looking for is, Just consider a bike game wherein the background road image moves while riding the bike. I just need similar implementation while scrolling the screen.
Maybe you could do like this:
RelativeLayout as the parent
ScrollView with your image set as background
Then the other views, but outside of the ScrollView and inside of the RelativeLayout.
EDIT:
<RelativeLayout
android:id="#+id/relParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<OtherViews />
<ScrollView
android:id="#+id/scrlParent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/yourbackground">
</ScrollView>
</RelativeLayout>
I think that something like this might work. You see, the RelativeLayout is the parent. Then comes your other views, on the top of your ScrollView. Then, after your other views tag, comes the ScrollView, with only a background. I'm not sure if a background tag would work, so maybe you should remove the android:background="#drawable/yourbackground" and put an ImageView inside of the ScrollView.
I am not able to scroll in a scrollview which contains a listview and is filled dynamically as I get data from the webservice.
I am able to do scrolling in emulator through mouse wheel, but in avtual device I can not scroll the list.
The attributes of scrollview are
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="0.6"
android:fillViewport="true"
android:orientation="vertical"
android:padding="6.0dip"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarFadeDuration="5000"
android:scrollbarSize="20dp"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="2dp" >
<ListView
android:id="#+id/listbox_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="599.84"
android:minHeight="250dp" >
</ListView>
</LinearLayout>
</ScrollView>
Please help me soon
by just looking at the layout_width and layout_height of your elements, it's clear that your scrollview will not scroll. unless you have a fixed height listview, never put a listview inside a scrollview (or in this case, a listview inside a layout that sits inside a scrollview).
I don't have any links to back this up right now, but it's not possible, and a well-known 'problem'. If you google a bit, or search here on SO, you'll find a number of topics covering this.
The problem arises in most cases when you have a scrolling view inside another scrolling view in the same direction. Consider the following example:
You have Two lists inside of a ScrollView.
Both lists are exactly one screen tall.
How do you scroll down to the second list?
When scrolling, how will your layout know if you are scrolling the list or the container?
This is basically the question that is the cause, and the only official solution is that it is as it should be, and there won't be a fix. Usually it is enough to have either a ListView or a ScrollView, but I have faced cases when you must have a listview in a scrollview (in my case a client wanted an iPhone-like datespinner in a scrolling page).
I solved it by using a FrameLayout, containing a custom ScrollView, and a ListView on top of that. Then in the code for the custom ScrollView, I added a line in the onScroll method that updated the top margin of the ListView, to psuh it upwards or downwards as the user scrolled. Surprisingly it worked.
NOTE: remember that:
The ListView handles its own scroll. If all you need is a scrolling
list, you do not need a ScrollView.
If you need a layout with a list and space for buttons or other
views, consider creating your layout so that the list only covers
enough space for you to fit your other views below/above without
scrolling.
Add following in your linear layout
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
ListView has this nice feature where you can set an overscroll header or footer. ScrollView, unfortunately, has no such thing. Does anyone know of a way to put together something that works like a ScrollView with an overscroll header/footer?
My best guess is you might be able to accomplish this with a similar approach as pull-to-refresh for lists is implemented on Android devices: you basically stretch a view at the top of (probably actually above - same for a 'footer', but then below) the ScrollView to fake an overscroll effect.
For some ideas on this, have a look at this pull-to-refresh implementation. It dynamically adjusts the padding of a header view in the list to simulate it being overscrolled when 'pulling'.
Can't you put your ScrollView inside a RelativeLayout, which will also contain the header and footer? Something like this:
<RelativeLayout ...>
<TextView
android:id="#+id/header"
android:alignParentTop="true"/>
<ScrollView
android:id="#+id/scroller"
android:layout_below="#id/header"
android:layout_height="fill_parent"/>
<TextView
android:id="#+id/footer"
android:layout_below="#id/scroller"
android:alignParentBottom="true"/>
</RelativeLayout>
In this question ( Can we use a ScrollView inside a LinearLayout? ), someone showed how to put a ScrollView inside a LinearLayout. It should be the same.
I have a WebView inside the ScrollView.
The content of WebView dyanamically changes when it displays different html page.
I have the following issue:
For example I have A.html, and B.html. The content of B.html is larger than A.html, so the page is longer.
When WebView load B.html, the ScrollView stretches its size to enable itself scroll for B.html, then if I go back to A.html, ScrollView doesn't resize itself. (The scroll area is exceed the content of A.html)
What I want to have, is dynamic change the scroll area of scroll view to fit the webview's content.
Try using android:fillViewport in scroll view..!!
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
After Orientation screen will resize, it works but bad in performance, not a very good solution
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_SENSOR );
This helped me:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
That's not good idea to place WebView inside of ScrollView. WebView is smart enough to show scrollbars by itself.
Don't put a WebView inside of a ScrollView.