Pass touch event down through Views and ViewGroup - android

I have a FrameLayout wiht a ScrollView and a LinearLayout inside.
Both ScrollView and LinearLayout have the same dimensions, so they are overlaid and the LinearLayout covers and hides the ScrollView.
The ScrollView has TextView and a Button inside itself.
This is the situation:
+FrameLayout
+ScrollView
+ LinearLayout 1
+ TextView
+ Button
+LinearLayout 2
Sometimes the LinearLayout2, which is on the top, is animated and goes out of the screen. For layout reasons I can't set it to GONE and this is the problem.
After the animation ends, the ScrollView is shown and I need to interact with the ScrollView, for example clicking the button and obviously scrolling, but all the events are always caught by the LinearLayout 2, because it always has the Visibility set to VISIBLE even if is actually hide out of the screen.
So, how can I pass the touch event down to the scrollview and its children?``
** EDIT **
This my XML. So you can understand better.
Which is the idea?
This layout is composed by 4 sliding drawer. When the user clicks on one of them, the drawer clicked goes up with animation and becomes a kind of header, the others go down out of the screen and they hide and the scrollview is visible ready to interact with the user.
For example: I click the second drawer, the third goes down, the disclaimer, the first goes up out of the screen and the second, which has been clicked goes at the top of the scree as an header. If I click again the second drawer, which is on the top now, I restore the initial layout as at the beginning, always with animation. To do that I add a Trasparent Layout, which has the same dimension of a drawer on the top, to handle click event, so I avoid to set a new layout whenever I animate the drawers.
What I want is to interact with the scrollview when it becomes visible and with all the stuff inside it.
PROBLEM: I can't set the drawers to GONE because the wieght parameter influences their height, but only to INVISIBLE. So, how can interact with the scrollview below?
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/programma_layout_root"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<!-- SCROLLVIEW HIDDEN FIRST LAYER -->
<ScrollView android:id="#+id/programma_content_scroll" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top">
<LinearLayout android:id="#+id/programma_layout_disclaimer_content"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:visibility="invisible">
<TextView android:id="#+id/programma_layout_disclaimer_content_text"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="some text..." />
<Button android:id="#+id/programma_layout_disclaimer_content_button"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center|bottom" android:text="CLICK" />
</LinearLayout>
</ScrollView>
<!-- LAYOUT FOREGROUND SECOND LAYER -->
<LinearLayout android:id="#+id/programma_layout_container"
android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
android:weightSum="19">
<include android:id="#+id/header_placeholder" layout="#layout/header" />
<!-- DISCLAIMER DRAWER -->
<RelativeLayout android:id="#+id/programma_layout_disclaimer"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="4" >
</RelativeLayout>
<!-- FIRST DRAWER -->
<RelativeLayout android:id="#+id/programma_layout_first"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="5" android:visibility="visible"
>
<!-- some stuff here (text, image...) -->
</RelativeLayout>
<!-- SECOND DRAWER -->
<RelativeLayout android:id="#+id/programma_layout_second"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="5"
>
<!-- some stuff here (text, image...) -->
</RelativeLayout>
<!-- THIRD DRAWER -->
<RelativeLayout android:id="#+id/programma_layout_third"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="5" >
<!-- some stuff here (text, image...) -->
</RelativeLayout>
</LinearLayout>
<include android:id="#+id/header" layout="#layout/header"
android:layout_gravity="top" />
</FrameLayout>

Related

How do I keep a button on screen which is below a listview when there are too many items in the list?

Quick background: I have a portion of my activity in a relative layout. I did this on purpose because I wanted a button directly below a listview. I want the button to move down as the listview expands which is why I set it up this way. I've set the height of the listview to wrap content, this way in the relative layout, the button will move down as the list expands.
Issue: Once the list gets big enough such that the content fills up the screen, the button remains below the list (which is fine) but I can't scroll down the list to reveal the button. The button "disappears" below the list. How can I make it so that I can scroll on the list/screen to reveal my button?
Edit: I do want the button to go off screen, I just want to be able to scroll down to see it again.
Sample code below + images:
3 pics, one showing the intial layout, next you can see the button moves as my list expands, 3rd, eventually the button reaches the bottom and I can't scroll more to click it.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/workoutList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/logExerciseButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/workoutList"
android:text="#string/log_set" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/workoutList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/logExerciseButton" />
<Button
android:id="#+id/logExerciseButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/log_set" />
</RelativeLayout>
wrap your ListView with ScrollView:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/workoutList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
<Button
android:id="#+id/logExerciseButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/scrollView"
android:text="#string/log_set" />
</RelativeLayout>
Adding the button as a footer to the listview resulted in the desired behavior: https://www.tutorialspoint.com/how-to-add-footer-in-android-listview

Black space during animation in LinearLayout

I'm using animation in LinearLayout in order to show and hide right pane. The layout consist of two elements: a map and right panel. When panel hides map immediately changes its size and then animation appears. Its OK.
But when the panel is showing the map shrinks immediately too therefore black space is shown when panel slides and it looks ugly.
The markup as follows:
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true">
<MapView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/map_view"
android:layout_above="#id/bottom_panel"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/right_panel"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:layout_weight="3">
<!-- Panel content -->
</LinearLayout>
</LinearLayout>
Here is the picture of what's going on during animation:
Can somebody help me with this? Thanks in advance!

Issue with overlapping ScrollViews

I must make a layout with 2 overlapping ScrollViews. One is an article with a "see comments" button. The other view is transparent and contains the comments, and is shown on top of the article when the "see comments" button is clicked. The problem is that when the comments are shown and do not fill the screen, touching the screen out of the screen (eg. below the button "Retour" on the image shown below. This is an iphone screenshot, the design on android is different) scrolls the article.
Also, the "Voir les Commentaires" button can be clicked, even with another layout on top of it.
Why is the view below not disabled (button, scroll...) when there's another one on top of it? How can it be done?
Anybody can help?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#FFFFFF">
<RelativeLayout android:id="#+id/header"
android:layout_width="fill_parent" android:layout_height="49dp"
android:background="#e7e7e8">
<!-- header -->
</RelativeLayout>
<ScrollView android:id="#+id/article_scroll"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_below="#id/header">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<!-- article -->
</LinearLayout>
</ScrollView>
<LinearLayout android:layout_width="fill_parent"
android:layout_below="#id/header" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#50000000" android:visibility="gone">
<ScrollView android:id="#+id/comment_scroll"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<!-- comments -->
</ScrollView>
</LinearLayout>
</RelativeLayout>
You should definitely use a new Activity for your comment and use Transucent theme:
<activity android:theme="#android:style/Theme.Translucent">
http://developer.android.com/guide/topics/ui/themes.html
Some alternatives Themes should fit your needs (Dialog for instance)
or a blurried background: http://www.stealthcopter.com/blog/2010/01/android-blurring-and-dimming-background-windows-from-dialogs/
As for the button "Voir les Commentaires", you could set it to enabled = false when the second layer is visible. And I'm not quite sure atm, but I think you can do the same for the bottom ScrollView.

Bottom bar in Android with different layout above?

I want to have a common bottom bar in Android. If any of the button is clicked then it should open up the new activity with bottom bar still at the bottom. Is there any way to achieve this? I have tried having a superclass with 4 buttons at the bottom and then opening new activity on click event but I do not know why the bottom bar is not displayed and also is this is the proper approach?
The way I did this was to have a single Activity consisting of a ViewFlipper which occupied most of the window, and the button bar at the bottom. The child "activities" were simply children of the ViewFlipper. Worked fine.
EXAMPLE ADDED LATER:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ViewFlipper
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<!-- Your pages go here, i.e.: -->
<include android:id="#+id/page1" layout="#layout/page1" />
<include android:id="#+id/page2" layout="#layout/page2" />
...
</ViewFlipper>
<!-- Your bottom bar -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
... buttons or whatever you want here ...
</LinearLayout>
</LinearLayout>

How do I make a Button a part of a scrollable ListView?

I have a ListView with a Button below it. When I fill the list with more content than the screen size allows, so that the scroll bar appears, the Button is not part of the scrollable area. That is, the Button disappears. How do I make the Button part of the scrollable area?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/ListView" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_above="#+id/AddButton" />
<Button android:id="#+id/AddButton" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="#string/add_title" />
</RelativeLayout>
Add it to the ListView as footer.
Add it with addFooterView(). This way it will always appear at the bottom of the screen while the ListView still scrolls.

Categories

Resources