Scroll view does not respond - android

Works great for portrait mode. If I go on landscape mode I have my activity drawn in the center of screen which leaves blank screen on both left and right side.
If I drag by keeping mouse on views (i.e. center)the scroll takes effect.
If I drag on empty right side no scrolling ? why ?
the image
posting my layout xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:id="#+id/enter_pin_scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarStyle="outsideOverlay" >
<RelativeLayout
android:id="#+id/enter_pin_header_layout"
android:layout_width="#dimen/pin_inset_region_width"
android:layout_height="#dimen/pin_inset_region_height"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal" >
<LinearLayout

Presumably, your ScrollView's width is set to wrap_content and thus, touch events outside of the dial pad are not taking any effect.
You can fix this by changing,
<ScrollView
android:layout_width="wrap_content"
... />
to,
<ScrollView
android:layout_width="match_parent"
... />

If every view is stored in the ScrollView, why not remove the RelativeLayout ? Have directly :
<ScrollView
android:id="#+id/enter_pin_scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarStyle="outsideOverlay" >
<RelativeLayout
android:id="#+id/enter_pin_header_layout"
android:layout_width="#dimen/pin_inset_region_width"
android:layout_height="#dimen/pin_inset_region_height"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal" >
If you want to keep it :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
Set the layout_height to fill_parent.

set your scroll view's width to fillparent not wrap content
android:layout_width="fill_parent"

Related

Android get screen size in XML

Hey I have a scrollview from the top of the screen to a bit before the bottom of the screen because this is where my ad banner takes place. I want to have some pixels in between these elements ( between buttons and banner ) due the google policy. So far I did this with setting a value in dp. But as devices differ, this results in having a huge gap between the ad and the scrollview on some hi-res phones. This is why I'd like to set
<ScrollView
android:layout_height="(Screen_height-banner)-5px"
(of course I didn't even try it in this way, as this is no code, but I think it sums up pretty well what I plan to do)
Thanks a lot for your answers!
You can't query screen size in XML since it doesn't run at runtime, you can do this by using RelativeLayout and use alignments and margins.
in your case if Screen_height-banner represent a screen height and you want to position it at bottom and make a 5dp separator from end your XML would be
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp">
</RelativeLayout >
If you need to scale the scroll view instead of position it you xml would be
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding_bottom="5dp">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</RelativeLayout >
You can user weight parameter. If you set weight of both layouts 0.5, this will share screen width equals for these layouts.
<LinearLayout
android:id="#+id/alt_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/orta_panel" >
<LinearLayout
android:id="#+id/altsol_panel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/altsag_panel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
Use a RelativeLayout, set a Margin of 5px and use layout_above
If the following codes don't work for you, you're probably using a newer version of something, and you could try using android:bottom="80dp" instead of android:layout_marginBottom="5dp"

Using ScrollView for scrolling an ImageView

I'm trying to create a layout which consists of one long image which should be scrolled vertically only.
I.e. - it should stretch to take the whole screen width and stretch for the full height.
My layout does this, but it creates strange gaps before and after the image. Each gap takes about 2/3 of the screen and can be scrolled down.
How can I remove the gaps so that only the ImageView appears on the screen?
My activity XML is like this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
tools:context=".HelpActivity" >
<ImageView
android:id="#+id/imageHelp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:src="#drawable/tutorial_with_text" />
</LinearLayout>
</ScrollView>
Found the solution: For future reference:
Use android:adjustViewBounds="true" on the ImageView

WindowSoftInputMode and ScrollView

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.

How to vertical scroll in Android Activity

I have the following layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:orientation="vertical">
<Gallery
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom" />
<LinearLayout
android:id="#+id/chart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
</LinearLayout>
Gallery is filled at runtime and when the user taps on an item I fill the LinearLayout with a series of images.
I would like to scroll vertically but if I add a ScrollView when the user taps the Gallery the LinearLayout is not filled anymore.
Is it normal? How can I add a vertical scroll?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView android:id="#+id/ScrlView" android:layout_width="fill_parent" android:layout_height="fill_parent" >
<LinearLayout android:id="#+id/layoutForScroll" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
>
<Gallery android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"/>
<LinearLayout android:id="#+id/chart" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Your vertical scroll view can only have one child, which means you need to envelop your gallery view and the linear view "chart" with another linerLayout which then should be enveloped with a scrollView.
When you add your new views, you may need to refresh the drawable state of the scroll view or invalidate it, try something like that, so that it expands accordingly.
You have to extend the Gallery class and in the Draw procedure rotate the canvas for 90 degrees. Then just a few adoptions like modifying the onTouch event and a few more is required. After this there will be a few problems with the layout (since it still wants to draw in the layout in its parameters). So I put it inside a LinearLayout and fixed the layout size in that.
So the final vertical gallery is actually a linear layout which has a gallery put inside it. I have implemented it, and it works quite well. You will only need to rotate everything you put in it for 90 degrees to the other direction. The trade off is really a little thus you can extend every view you want to put inside it and just rotate it to the other direction in the draw procedure.

horizontalscrollview's fillviewport disables scrolling?

I have this layout, and it's scaled weirdly (probably due to inadviseable layout nesting) if I do not use fillviewport=true in my HorizontalScrollView.
Everything works peachy (except for the odd scaling) when fillviewport=false, but when fillviewport=true, the scaling is perfect but no scrolling happens.
This is the layout (Note: I know you're not supposed to put a webview in a scrollview. But webview doesn't have a smoothscrollto nor expose a setscroller method, so ... bleh.)
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webContainer"
android:layout_below="#+id/titlebar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<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>
Setting android:fillViewport="true" doesn't usually disable scrolling in a view, does it?
It's just supposed to be sure the scrollview fills the viewport regardless of the size of its contents, eh? I think the viewport is the visible area of the screen, and there is definitely more content off the edge of the visible area in the webview, I just can't scroll to it anymore.
I can see from logcat that the scrolling methods are being called, they just don't change the screen. (Unless I set fillviewport to false.)
The problem is that you use "fill_parent," which means "be as big as my parent." Use wrap_content for the width instead.
I encounter a similar problem with a standard ScrollView containing a WebView: the scrolling was not working anymore. Changing of fill_parent to wrap_content did not worked for me.
The example of Romain Guy is working fine when the expanded view is a TextView but is not when it's replaced by WebView.
What is not working:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<WebView android:id="#+id/webview"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1.0">
</WebView>
<Button
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Click">
</Button>
</LinearLayout>
</ScrollView>
When I add a small amount of data in the webview it seems ok:
But when I fill the WebView with a lot of data, it does not work as you can see below:
The button is always displayed and the scroll does not work anymore. In fact, the touch scroll does not work and the DPAD scroll works...
I did not found any reason for that but I found a workaround: it consist in adding a LinearLayout containing the WebView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:id="#+id/linearlayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="vertical">
<WebView android:id="#+id/webview"
android:layout_width="fill_parent" android:layout_height="wrap_content">
</WebView>
</LinearLayout>
<Button
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Click">
</Button>
</LinearLayout>
</ScrollView>
Now it works fine:

Categories

Resources