There were some questions about ScrollViews inside Gallery etc., however I have something exactly opposite here and I can't find any solution.
The problem: I have multiple Galleries in one ScrollView. Horizontal scrolling for Galleries works fine (nothing changed here, just a standard Gallery class from SDK), but vertical scrolling for ScrollView, for whole activity does not. It looks like Galleries are intercepting touch events. Could you please help me to solve this out?
This is my layout xml:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/layout_home"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
...>
<Button
.../>
<Gallery
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gallery_..."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
... />
<TextView
... />
</RelativeLayout>//this layout is repeated few times, because I have multiple galleries
</RelativeLayout>
</ScrollView>
Thanks!
You could make the top RelativeLayout (which contains all the other RelativeLayouts), to be about 30-40 dp smaller in width then the ScrollView. This allows the user to touch an area of the ScrollView which is not covered by a Gallery, so the Touch is not intercepted and should work as expected.
Related
I have a nestedscrollview in my fragment which is having button below of nestedscrollview, when keyboard arrives button moves above of the keyboard and the entire layout handle its scrolling properly but the issue is with the background image which get shrink.
I've used android:windowSoftInputMode="stateAlwaysHidden|adjustResize" in my Manifest file and if i use adjustPan then view does not scroll entire layout shift up.
I know this question is asked so many times but I didn't found proper answer.
Please Help.
Follow steps like below :
After that you are able to achieve what you want:(Below code is MainActivity.xml code)In this code Image View is your background image.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAppBack"
tools:context=".activities.LoginActivity">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/login_image_min_2" />
</ScrollView>
// Your container layout which contains fragments like framelayout or what ever you are using
</RelativeLayout>
In manifest:
android:windowSoftInputMode="adjustResize"
Your image is shrinking because you have added image inside scroll view too.
Try to add image out side the scroll view as image is background image.
This way Image wont scroll.
My Layout has a few complex layouts and they are pretty big. That's why I need a ScrollView. But whatever I try it doesn't work.
Here is my layout file:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_weight="1"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:id="#+id/Linear1"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#color/tileColor1"
android:layout_weight="1"
android:id="#+id/tileLayout1"
android:onClick="openFirst"
>
I have only posted a part of it but all the closing tags are ok and inside my RelativeLayout there are 2 textViews and an image. There are 9 more RelativeLayouts with the same structure.
How can I fix the problem and why doesn't it work? It doesn't even show a scrollbar.
EDIT
I have uploaded my full layout to pastebin
EDIT 2
On the developer.android it is said:
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
Mine doesn't deal with the scrolling at all. I suppose it is this way because I edit LayoutParams in code. How do I fix this?
1. Try removing android:layout_weight="1" and android:orientation="vertical".
2. Ensure that there is only one ViewGroup inside the ScrollView (i.e. one child as they say). I assume you've done this, but as you haven't provided your full layout I couldn't confirm it.
ScrollView only accepts one child view. So wrap everything inside it in a LinearLayout with wrap_content set as height and you're set.
I had the same problem, and I do not know if my solution helped (mainly because it is a very late response), but my ScrollView not worked since set up a layout that fit exactly on the screen, so it was not necessary to create scrolling. When increased my layout (I put all my items with
android:layout_height = WRAP_CONTENT) became operational.
I have a really annoying problem with fitting two custom views to work together. I'm trying to display these two views in an android activity, but one of them takes the whole viewable space of the activity and the other is placed under it. The first view only uses a small part of the space and the rest is trasparent, but it only works when its width and height is at match_parent so the other view is displayed under it, but it is being blocked from receiving any touch events. here is how they looks like:
the xml code:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_app" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.fortysevendeg.android.swipelistview.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="#+id/example_lv_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="#00000000"
swipe:swipeActionLeft="dismiss"
swipe:swipeBackView="#+id/back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="#+id/front"
swipe:swipeMode="both"
android:focusableInTouchMode="true"/>
</LinearLayout>
<com.touchmenotapps.widget.radialmenu.semicircularmenu.SemiCircularRadialMenu
android:id="#+id/radial_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:padding="1dip" />
</FrameLayout>
What I'm trying to do is to be able to touch the bottom where the top view is transparent, and be able to touch the top view where it's not transparent. I tried arranging the xml in a different way but it keeps crashing, this is the only way it worked, but this problem appeared.
Links to the custom Views:
Radial-Menu-Widget: github.com/strider2023/Radial-Menu-Widget-Android
SwipeListView library: github.com/47deg/android-swipelistview
SwipeListView sample: github.com/47deg/android-swipelistview-sample
What I'm trying to accomplish here is something similar to Catch Notes app. If there are other ways, or other libraries you can suggest, it would be much appreciated.
Ok try this: copy the source code of SemiCircularRadialMenu.class in your project and modify
public boolean onTouchEvent(MotionEvent event)
Because this method always returns true and captures all touch events, so also the touch event for SwipeListView listener. I solved it in this way.
An old question, but others may find this answer helpful. Without modifying the source of your custom views, I don't think you can get the behavior you want. But getting the two custom views to work onto the same screen might be as simple as changing your root layout to a LinearLayout, adding weight to the inner layout, and setting the height of the second custom view to wrap_content. By having only one widget with a weight, it will get all the space left after the others are laid out. Here's your layout with the changes applied:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_app"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="100" >
<com.fortysevendeg.android.swipelistview.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="#+id/example_lv_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusableInTouchMode="true"
android:listSelector="#00000000"
swipe:swipeActionLeft="dismiss"
swipe:swipeBackView="#+id/back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="#+id/front"
swipe:swipeMode="both" />
</LinearLayout>
<com.touchmenotapps.widget.radialmenu.semicircularmenu.SemiCircularRadialMenu
android:id="#+id/radial_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="1dip" />
</LinearLayout>
If you need to height of the second view to be more expandable, you can wrap it in another LinearLayout with a weight and adjust the two weights to apportion the screen height between them. The individual weight values aren't special; it's their value relative to the sum of all the weights that determines how much height each one gets. I like to make my total values add up to 100 so I can think of the weights as percentages.
when I turn the phone and the screen is rotating I cannot see the whole screen anymore. This is ok but I cannot scroll! Do I have to set some flag or property for scrolling? This is part of my xml...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="*">
...
</TableLayout>
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
...
</TableLayout>
</LinearLayout>
Thanks!
You have to put your complete layout inside a ScrollView in order for it to scroll.
It scrolls if your layout height is more than the screen height, which happens generally in landscape mode.
In your case put the LinearLayout inside a ScrollView, since ScrollView can only have 1 child.
You must know that in order to use an scrollView , you must put only one component inside (maybe a linearLayout) .Maybe that's your problem if you are trying to put in more components at that level.
I have a little problem with a ScrollView. I have a layout for an activity which is made with a ScrollView. This scrollview contains two ListViews.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootViewGroup" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="vertical">
<LinearLayout android:orientation="vertical"
android:gravity="top" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#drawable/cmb_bg">
<ListView android:id="#+id/accountsListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="none" />
<ListView android:id="#+id/cardsListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="none" />
</LinearLayout>
In the onCreate method of my activity I compute ListViews height according their contents.
During execution, on activity launch, ScrollView is already scrolled a bit.
So I tried, at the end of onCreate to call method scrollTo(0, 0), but it does not change anything.
Any ideas?
AHHH!!! Remove ScrollView and leave only ONE ListView in your activity. It's not intended to work this way
.If you want to have different content in your ONE listView - modify your adapter, or change the UI
But never, ever put different scrollable containers on the same screen/inside each other
here is a related post.
http://groups.google.com/group/android-developers/browse_thread/thread/e7c8df374fe31733#
In theory you can slap two listview on the screen, but expect things to be weird. And i would really redesign it with with either separators or expanders or just with one ListView.