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>
Related
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>
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.
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).
How can I scroll a LinearLayout in a ScrollView to the bottom of Another View?
I have a calendar imageview at the top of my view. Underneath there is a ScrollView that contain a list of events for that month. The ScrollView contains several LinearLayouts that detail the events for that month. When the user selects an event by touching a button in the linear layout I would like to re-position the current linearlayout to the top of the scrollview, how can I accomplish this?
Below is a brief snippet of what my layout looks like for brevity.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cirLinLayContainer"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg_calendar">
<RelativeLayout>
<Button
android:id="#+id/calLeft"
android:background="#drawable/btn_arrowleft_dwn"/>
<Button
android:id="#+id/calRight"
android:background="#drawable/cal_rightnav_button"/>
<ImageView android:src="#drawable/cal_september"
android:layout_width="match_parent"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content" />
</RelativeLayout>
<ScrollView xmlns:foo="http://schemas.android.com/apk/res/com.demo.android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/septemberCalendarScroller">
<LinearLayout android:id="#+id/sepEventLayout01"/>
<LinearLayout android:id="#+id/sepEventLayout02"/>
<LinearLayout android:id="#+id/sepEventLayout03"/>
<LinearLayout android:id="#+id/sepEventLayout04"/>
</ScrollView>
</LinearLayout>
You could measure the height of your linearlayout elements and than use ScrollView.scrollTo() to position the scroll view accordingly.
I want the footer to be anchored at the bottom of the screen if and only if it can be anchored there without overlapping any other views.
The problem is that I don't know how many views are going to be added to the header or the footer.
If putting the footer at the bottom of the window would make it overlap, I want to put the footer at the bottom of the scrollview. (Maybe by adding it to the RelativeLayout with the rule that it needs to be below the top component?)
Here is a pic of what I'm trying to get:
desired result
Where:
1)The RelativeLayout contains both the TableLayout at the top, and the LinearLayout at the bottom.
2)The TableLayout expands downwards as TableRows get added to it.
3)The LinearLayout expands up from the bottom as views get added to it.
~~~
I'd like for the scrollview to grow in size only enough to fit the components without overlapping.
Thanks in advance for such awesome community support
I think you can solve it in linear layout. You set three blocks in linear layout: header, body, footer. Set body to fill_parent and layout_weight=1, this way body will expand to fill what left after header and footer taken its part from parent. Whole structure place into ScrollView.
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow><TextView android:text="Text1"/></TableRow>
<TableRow><TextView android:text="Text2"/></TableRow>
</TableLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="#string/lorem_ipsum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="Text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
I tested this in Emulator of Android 2.1 and it looks it works.