Android scrolling - android

Everybody know how Rubik's cube works.
Is it possible to do somenthink like that in android:
I have 5 on 5 square buttons. Is it possible to rotate them as Rubik's cube (2D)?
If i have something like this:
<ScrollView android:id="#+id/scrollView1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical">
<HorizontalScrollView android:id="#+id/horizontalScrollView1"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:id="#+id/linearLayout2"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
It's possible to scroll lines vertically or horizontally. But i want to scroll objects somtimes horizontally and somtimes vertically. How can i do that?

No it wont work like that. Scroll in scroll doesn't work well on Android. In order to do something like that I'd suggest you make your own type(s) of ScrollView where you look at the direction of the scroll and based on that input scroll or don't scroll.

Related

LinearLayout does not return onFling?

I expect to display one picture each time and horizontally swipe to another picture through onFling(). The problem is I have to use ScrollView to wrap my ImageView so as to get response from onFling. If I use Linearlayout to wrap the ImageView, nothing happens when I swipe. I don't want to use scrollview because the picture can be scrolled vertically though it is the exact screen size. How can I achieve it? Below is my layout.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/iv_tutorial"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
I fixed it by adding an attribute android:longClickable="true" to the LinearLayout.

how to get Horizontal and Vertical Scrollable list in android?

i am developing an android app where i am showing day wise channel schedule (multiple rows).
now in this i have to provide both vertical and horizontal scrollability.
vertical scrollability will be normal , but horizontal scrollability should be synchronized
that is when user scrolls horizontally all other rows should also be scrolled in a sync.
i tried using table layout but its not going good with my requirement and i have also tried TwoWayView but i am not able to sync the horizontal scrolling.
i would like to know i anyone have faced/solved the similar situation.
Any leads on this is highly appreciated.
xml for vertical and horizontal Scrolling :-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/vertical_scroll_view2">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/horizontal_scroll_view2">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="910dp"
android:id="#+id/scheduleContainer"
android:orientation="vertical"
/>
</HorizontalScrollView>
</ScrollView>
.....
xml for TwoWayView:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/weekday"
android:layout_height="fill_parent"
android:layout_width="40dp"
android:textSize="12dp"
android:textStyle="bold" />
<com.mobiotics.tvb_stb.utilityclasses.TwoWayView
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/hlist"
style="#style/TwoWayView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/weekday"
android:scrollbars="none"
android:drawSelectorOnTop="false"
tools:context="com.mobiotics.tvb_stb.activity.HomeScreenActivity" />
</RelativeLayout>
i am adding twoway list to linear layout .
If you can have a ListView, I would start there. Just drop the ListView into a HorizontalScrollView. Make sure to set the width of the HorizontalScrollView to wrap_content. I noticed you have it set to fill_parent.

Android, Horizontal and Vertical Scroll for GridLayout

I'm having trouble getting a GridLayout to scroll horizontally.
I found a similar question Gridlayout + ScrollView. I tried that method, but it didn't work.
It cuts out many tables (because it was supposed to go display all tables from 1 to 20).
Here is the xml file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="16dp" >
<android.support.v7.widget.GridLayout
android:id="#+id/table_mapGrid"
android:layout_width="250dp"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
<include layout="#layout/cell_list_loading" />
<TextView
android:id="#+id/table_errorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:text="#string/message_error_connection"
android:visibility="invisible" />
</FrameLayout>
I want to have dynamic content displayed, varying the number of columns and rows possibly with empty spaces between tables.
This I have accomplished, but the problem is when the width of the GridLayout becomes greater than its container's, I wanted to solve that using horizontal scroll, but it doesn't seem to work...
Any suggestion?
Well I found the solution
It seems like the android ScrollView works as a VerticalScrollView and only that (the name is not so intuitive as HorizontalScrollView).
So to make something scrollable vertically and horizontally, you need to nest a (Vertical)ScrollView inside a HorizontalScrollView, or the other way around, like this
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent">
<!-- Your content here -->
</HorizontalScrollView>
</ScrollView>
The nested HorizontalScrollView / ScrollView will not allow you to scroll both directions at the same time.
I had this problem and created a custom component for that, here is the link if it can help anybody :
https://gist.github.com/androidseb/9902093

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