Scrolling Android ScrollView to X-axis and Y-axis - android

In my Android app I wanna use a ScrollView and it must be scrollable to both X-axis and Y-axis. Without using both ScrollView and HorizontalScrollView as I did cant I use one ScrollView and enable both scrolls. What I did is below.
<ScrollView
android:id="#+id/srv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ll1" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical" >
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
Is it possible to use just one scroll view and enable both scrolls. Thank You!!

AFAIK, No.
ScrollView is for vertical scrolling, as is ListView.
HorizontalScrollView is only for horizontal scrolling.
To implement both x and y axis scrolling, you must use both ScrollView and HorizontalScrollView as you have done.

Related

Android HorizontalScrollView appearing as Vertical

Hi I want to create a horizontal scrollview but it comes out as vertical. Can you help?
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<ListView
android:id="#+id/household_member_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</HorizontalScrollView>
Here is what appears:
Please help. Thanks.
You are using ListView inside of ScrollView, this will not work.
If you want to have horizontal ListView you need to use RecyclerView
More here:
Horizontal ListView in Android?
You can use recyclerview.
Set horizontal linear layout as layoutmanager for recyclerview to achieve horizontal scrolling

How to use Horizontal ScrollView With one Fixed layout positioned at center?

I wanna implement the horizontal layout with fixed layout that is positioned at center. But the problem is that when i kept the layout at the center the horizontal scrollview child layout will be overlap by the fixed layout that i have kept on center. How to separate the space on horizontal scroll view so that while scrolling the scrollview child will jump the the space that we have define and position at the right and left of the center layout.
How can it be possible? Please Give some idea. Happy if you provide me code. Hope with positive response.
Try to use FrameLayout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="#color/main_background"
android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"></HorizontalScrollView>
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:srcCompat="#android:drawable/ic_delete" />
</FrameLayout>
Hope this may help.
You can make use of FRAME layout, keep imageview gravity at center - rest of the horizontal scrollview as it is.
For reference check the below code
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"></HorizontalScrollView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#android:drawable/ic_delete" />
</FrameLayout>

Is it possible to attain diagonal scrolling using ScrollView and HorizontalScrollView?

I have a layout file having both ScrollView and HorizontalScrollView. And am able to scroll either in horizontal direction or vertical direction. Will it be possible to scroll diagonally?
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Customview..../>
</HorizontalScrollView>
</ScrollView>

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.

How to scroll a LinearLayout horizontally?

I have a LinearLayout that I do larger than the screen. I want to scroll that in horizontal. I have the next code but it doesn't work. Can anybody help me?
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/gm_movimientos"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
Your HorizontalScrollView width needs to be set to either match_parent or a fixed size. Right now the ScrollView is expanding to the same dimensions of the LinearLayout (i.e. its bounds are also going off of the screen).

Categories

Resources