I have a LinearLayout which needs to be clickable inside a NestedScrollView inside a CoordinatorLayout and almost all the time the first time I click it it simply doesn't work, I must click it another time.
Clickable LinearLayout:
<LinearLayout
android:id="#+id/qr_code_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
tools:ignore="UseCompoundDrawables">
This is the NestedScrollView container where
the clickable item resides.
EDIT: Okay this is very weird, if I wait some seconds before trying to click the View, it works the first time. It only fails if I click it just after scrolling to the bottom.
I had the same problem. Inside the NestedScollView there was a RelativeLayout element needed to be clicked. As long I didn't scroll to the very bottom, the element could be clicked with a single click. If I would reach the bottom I needed two clicks, except if I waited a number of seconds.
The problem proved to be on the default layout_behavior of the AppBarLayout. I used the custom one suggested in the post below and the problem was solved.
onClick method not working properly after NestedScrollView scrolled
Related
I have a recycle view horizontaly which sometimes contains one or two elements and may not cover entire screen.
I want to handle click for the rest of empty space on right but since by default recycler view is match parent the click listener on container does not work.
Is it possible to stop recycler taking click entirely and its parent container (say Linear Layout) handle click
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_friend_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="#dimen/ad_detail_friend_recycle_min_height" />
</LinearLayout>
I have tried making recycler element as disabled and even whole recycler list clickable and focusable false.
Hey the problem lies with the fact that you are not able to set property wrap_content to the width of the recycler view(https://code.google.com/p/android/issues/detail?id=74772)
However there is a workaround for the same available here which is to set a custom layout manager which shall enable you to set the wrap_content property to the recycler-view. Now set a click listener on the linear-layout and you are good to go.
Now, there is another way which i'm not sure will work, but what if you set a onclicklistener on the recycler-view itself??;-)
Thanks to the new support library 23.2.0 this issue is fixed now.
I have to an EditText behind a ScrollView
I cannot click the EditText anymore. The ScrollView is intercepting it I think. I tried the code below but it doesn't fix it.
Any suggestions?
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:layout_alignParentTop="true" >
Things to try:
The parent view can influence the position of the views. For example
in a FrameLayout all of the views get stacked in the order they are
placed in the layout file (so your issue could be fixed by
rearranging the order of the EditText in relation to the
ScrollView).
You might try to call editText.bringToFront() to force the
EditText in front of the ScrollView.
If you disable the touch-based listeners (OnClickListeners, etc) on
the ScrollView or the container it's in then the action should "pass
through" the ScrollView and allow you to interact with the EditText
behind it. I found this out the hard way when I was trying to make
the opposite scenario work for me (I wanted the top level view to
consume the actions and not fall through to the view behind it).
These solutions worked for me in the past in different scenarios.
In my case I replaced android:layout_height="match_parent" to android:layout_height="wrap_content" and views inside ScrollView become clickable. Hope this helps.
My code:
v<ScrollView
android:layout_width="match_parent"
android:layout_height="WRAP_CONTENT"
android:id="#+id/svTabActions">
<View>...</View>
</ScrollView>
Try placing the editText inside the scrollView.
I have an ExpandableListView and I am using a SwipeDetector to know when a row of this list is swiped.
The implementation of this dectetor comes from this post.
Everything works fine.
Then, I have added a Button on each row and I want to be able to know:
When the button is cliked
When the row is swiped
This is the layout used for each (except for headers) row of the list:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#fff"
android:layout_height="wrap_content" >
<Button
android:text="Button"
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Now, the problem is that the swipe gesture is no more detected because the Button catches the event. Since they are lots of threads about this subject I tried several things but nothing works (at least I did not manage to make it work). Here is the different things I tried:
Set the android:focusable property to false on the Button
Set the android:descendantFocusability property to blocksDescendants on the RelativeLayout
Follow this post and override the onInterceptTouchEvent
Last points:
I can't set the SwipeDetector directly on the Button instead of the ListView's item because in some cases there will be no button (or many).
I can't use android:clickable="false" on the Button because I need to implement the onClick method.
I want a ListView to fill the space available to it while still leaving room for a small footer view at the bottom of the screen. I'm trying to use a RelativeLayout to accomplish this and attempted to use the solution discussed at Limit number of rows of listview . The problem I'm running into is I'm using nested Fragments, so my ListView is actually a FrameLayout in my xml then I load a ListFragment into that frame dynamically. Given the nested fragment stipulation, how can I get my FrameLayout to "stackFromBottom" as I would with a ListView? I just need to stop the list from pushing the other View off the bottom of the screen. Thanks for your time all.
Here is the solution I came up with:
<TextView
android:id="#+id/advertisement"
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="Ads will appear here"
android:gravity="center"
android:layout_alignParentBottom="true"/>
<FrameLayout
android:id="#+id/news_frag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/carousel_menu"
android:layout_above="#id/advertisement"/>
The trick was to set both layout_above AND layout_below for the FrameLayout, I had only been setting one and that was apparently allowing the layout to push it off of the screen. Also worth noting is they had to be declared in reverse order of how they actually appear on the page, so that the FrameLayout could properly reference the other View.
I am not able to scroll in a scrollview which contains a listview and is filled dynamically as I get data from the webservice.
I am able to do scrolling in emulator through mouse wheel, but in avtual device I can not scroll the list.
The attributes of scrollview are
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="0.6"
android:fillViewport="true"
android:orientation="vertical"
android:padding="6.0dip"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarFadeDuration="5000"
android:scrollbarSize="20dp"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="2dp" >
<ListView
android:id="#+id/listbox_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="599.84"
android:minHeight="250dp" >
</ListView>
</LinearLayout>
</ScrollView>
Please help me soon
by just looking at the layout_width and layout_height of your elements, it's clear that your scrollview will not scroll. unless you have a fixed height listview, never put a listview inside a scrollview (or in this case, a listview inside a layout that sits inside a scrollview).
I don't have any links to back this up right now, but it's not possible, and a well-known 'problem'. If you google a bit, or search here on SO, you'll find a number of topics covering this.
The problem arises in most cases when you have a scrolling view inside another scrolling view in the same direction. Consider the following example:
You have Two lists inside of a ScrollView.
Both lists are exactly one screen tall.
How do you scroll down to the second list?
When scrolling, how will your layout know if you are scrolling the list or the container?
This is basically the question that is the cause, and the only official solution is that it is as it should be, and there won't be a fix. Usually it is enough to have either a ListView or a ScrollView, but I have faced cases when you must have a listview in a scrollview (in my case a client wanted an iPhone-like datespinner in a scrolling page).
I solved it by using a FrameLayout, containing a custom ScrollView, and a ListView on top of that. Then in the code for the custom ScrollView, I added a line in the onScroll method that updated the top margin of the ListView, to psuh it upwards or downwards as the user scrolled. Surprisingly it worked.
NOTE: remember that:
The ListView handles its own scroll. If all you need is a scrolling
list, you do not need a ScrollView.
If you need a layout with a list and space for buttons or other
views, consider creating your layout so that the list only covers
enough space for you to fit your other views below/above without
scrolling.
Add following in your linear layout
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"