Is It possible to click through a ListView? - android

I have a ListView over a LinearLayout. There are clickable elements in the LinearLayout and since the ListView is transparent I can see those elements, and would like to be able to click on them, but even though the ListView looks transparent, it behaves as a barrier and doesn't let me click on the elements.
Is there a way I can click through the ListView?
If I change the ListView layout_height to wrap_content, it behaves as I want, but I need it to start with a certain height, so the items will stack at the bottom with android:stackFromBottom="true".
This is an example of how the code looks like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
(Clickable elements)
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:transcriptMode="normal"
android:layout_marginTop="100dp"
android:layout_marginBottom="361dp"
android:stackFromBottom="true"
android:listSelector="#android:color/transparent"/>
</RelativeLayout>

Extend listview and override the onTouch() method and pass it down to the underlying views

Related

Remove left space between ListView border and Items

Can somebody tell me how can I remove the space between the listview border and the items inside the listview?
Remove margins from your xml listview layout.
If I understand your question properly, you are not looking for removing space between listview border and items (The red sign on your image says that! you want to remove space between two elements inside 1 item). If that is true, then you have to go to the custom layout file you created to set as a row for the listview. It looks like you have 2 TextViews there ("Go" and "Bro1, Bro2......"). There you have to play with the Margin-Up and Margin-Bottom of these 2 textviews.
android:layout_marginBottom="1dp"
android:layout_marginUp="1dp"
If you mean the space around the listview then either check the margins of the listview or paddings of the parent layout of the listview.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="0dp">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp" />
</LinearLayout>
</RelativeLayout>

Recycler view notifyItemInserted empty space

I have an issue where i would like to fill the expanded space with a custom color or gradient in that matter. However RecyclerView works in a way that it expands the rows by leaving an empty space between items which results in seeing a white background (screenshot) or whatever is the background color. The empty space gets filled after the expansion animation, where onBindViewHolder gets called.
Could this be solved somehow, where I could fill this empty space with a custom view, so it gets epxanded nicely without color flickering?
Is there a way I could attach a listener to the animation and overlay it with a virtual view for that time?
Right before the child views are shown:
After the child views are shown (group is expanded)
EDIT: added RecyclerView's xml as requested
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
style="#style/myRecyclerViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
group_item.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/list_group_item_height"
android:background="#android:color/holo_green_light"
android:clickable="true"
android:foreground="?attr/selectableItemBackground">
<TextView
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
</FrameLayout>
child_item.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/list_item_height"
android:background="#android:color/holo_green_light"
android:clickable="true">
<TextView
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
</FrameLayout>
Even if i change all the heights to wrap_content its still the same, the animation just epxands the views and leaves an empty space (recyclerView's background), which i would like to fill somehow.
This is taken from this library: https://github.com/h6ah4i/android-advancedrecyclerview
This should be because you might have given match_parent in your adapter classes. Hope this is helpful :)

Listview and TextView alignment

I have a listView which takes data from a rest API server and displays it. I need to add a textView on the side of it describing the type of data.
The right half of the screen has the listView and the left half has the textView.
The problem arises when the textView moves to accommodate the different screen sizes. I need the textView to be fixed and to be shown in conjunction with listView, and be in a straight line with the listView, regardless of the screen size. Cheers.
Edit: Image added of the sketch
It sounds like a ListView is not what you want to use. You cannot align Views with the children of a ListView. You would need to either put the TextViews within the ListView's children or not use a ListView.
The simplest way to do this would be a vertical LinearLayout containing many horizontal LinearLayouts.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"/>
<Item that was in the ListView />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"/>
<Item that was in the ListView />
</LinearLayout>
...
</LinearLayout>
The ListView is really for scrolling and when you don't know how many items there will be.
Perhaps you already have an adapter in which you are handling the creation of the items and that's why you are using a ListView. You can still create the LinearLayout's children programmatically by inflating each item individually and adding it to the container view.
Original Answer:
You probably want the TextViews to scroll with the ListView as well. So I would think you should use one ListView, then add the TextView to the left side of the ListView item.
You should use weightSum,
Here is an example.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="horizontal">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hello World"/>
</LinearLayout>

Scroll ListView instead of his Items

I have a layout which is divided in other two layouts: a LinearLayout for the "Header" and a RelativeLayout for the "Content".
In the content layout I have a ListView that needs to grown when the user scrolls, and hide this same ListView behind the header layout.
Basically, I need something like this:
What would be the best aproach to do something like this? This is my layout.xml right now:
<LinearLayout
android:id="#+id/layout_full"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_base"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:weightSum="1"
tools:context=".app.Main">
<!-- Header -->
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".55"
android:background="#drawable/background_header_small"
android:gravity="center_horizontal">
</LinearLayout>
<!-- Content -->
<RelativeLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight=".45">
<ListView
android:id="#+id/listview_full"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/text_add"
android:layout_alignEnd="#+id/text_add"
android:layout_alignStart="#+id/text_add"
android:divider="#null"
android:dividerHeight="0dp"
android:showDividers="none"
android:layout_marginBottom="10dp"
android:footerDividersEnabled="false"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
</LinearLayout>
Can I somehow remove the elevator component of the ListView, and scroll the ListView instead of the Items inside the ListView?
Apologies, I can't comment yet. But you probably want to use the CoordinatorLayout as your parent, instead of the LinearLayout you're using now. From there you have two options: the hackier way is to use a transparent CollapsingToolbar that is placed underneath the header, the other way is to create your own Behavior that will increase the high/top of the List.
This is under the assumption that the ListView will continue to scroll as normal when the the top of it reaches the top of the screen?
I can throw something together when I get home if this seems like it's on the right track.

Receiving click/swipe events on a view behind a transparent item of a listview

I have a layout similar to Foursquare (image), where a View (in their case, a map) is behind a ListView, but is visible because the first element is transparent.
I need the View behind the ListView to take touch and swipe events. Is there a way to make only that first invisible item of the ListView ignore these events and allow the events to propagate to the View behind it, but have the rest of the ListView items take the events as usual?
I'm just hoping I won't have to completely abandon the ListView and use a ScrollView instead, because I've already implemented a lot of ListView specific features.
ScrollView on the back will work normaly unless you click the button:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/text"
android:text="asdfasdfa Put more text for testing sdfasdfasdfasdfasdfff
afdasdfasdfasdfasdfasdf
asdfasdfa"/>
</ScrollView>
<LinearLayout
android:id="#+id/top"
android:layout_height="match_parent"
android:layout_width="match_parent">
<Button
android:id="#+id/butt"
android:layout_height="100dp"
android:layout_width="200dp"
android:text="Test"/>
</LinearLayout>
</FrameLayout>
Both of the layers/frames have height and width set to match_parent (full screen in this case). And you can basicaly put anything you want into both of this layers as you need it.

Categories

Resources