LayoutTransition: 2 containers - android

I'm trying out an official example on LayoutTransition. I've modified it in order to have 2 containers. I add new items to 1'st (top) container with animation and the 2'nd (bottom) container moves down with slide animation, as expected.
But when I remove item from 1'st container, the whole 2'nd container goes beneath 1'st container, while 1'st container is shrinking height with animation (while animation is playing last element of 1'st and first element of 2'nd are intersecting).
Is there any way to make 2'nd container slide up while 1'st container is shrinking?
layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff">
<ScrollView android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="#+id/container1"
android:background="#drawable/border"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:showDividers="middle"
android:divider="?android:dividerHorizontal"
android:animateLayoutChanges="true"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
</ScrollView>
<ScrollView
android:layout_width="match_parent" android:layout_height="wrap_content">
<LinearLayout android:id="#+id/container2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:showDividers="middle"
android:divider="?android:dividerHorizontal"
android:animateLayoutChanges="true"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
</ScrollView>
</RelativeLayout>

This may not be the correct answer and it's definitely too late for this answer but it might be helpful and I had a similar issue where one item was disappearing and I wanted the second item to expand while the item was disappearing. I used setStartDelay() of LayoutTransition in code for both LayoutTransition.CHANGE_DISAPPEARING and LayoutTransition.DISAPPEARING to 0, as well as setDuration() of both to the same value. You might have to mess with those values for LayoutTransition.CHANGING, since that affects expanding views, but honestly LayoutTransition may not be capable of it (though I definitely don't know for sure), because while the expanding view is DEFINITELY CHANGING, the second item moving up is probably not CHANGE_DISAPPEARING, though you want a similar animation.
my code:
customTransition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
customTransition.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);
customTransition.setDuration(LayoutTransition.DISAPPEARING, hideArticleBar.getDuration());
customTransition.setDuration(LayoutTransition.CHANGE_DISAPPEARING, hideArticleBar.getDuration());

Related

scroll ListView inside a LinearLayout which is wrapped in ScrollView

I have an activity which should be scrollable, therefore i surrounded it with a ScrollView. I have two listViews in there, which i do not want to be as large as it would be necessary to display all items.
It would be nice if i could set a maxHeight property, so that in case there are only 2 items no empty space would be present, but if there are 50 items i would only want to see like 5 of them at a time. Unfortunately there is no such property, so i decided to just set the height to a fixed number. Any advice how to do that more properly would be much appreciated.
However the main problem is that, when i try to scroll one of the listViews the whole LinearLayout scrolls down. (I can avoid this if i use another finger to 'hold' the LinearLayout in place while scrolling the list, but that certainly not a solution.)
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="app.ballmaschine.pages.SettingsPage">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Some other stuff here -->
<TextView
android:text="Eine Maschine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"
android:layout_marginTop="8dp" />
<ListView
android:layout_width="match_parent"
android:id="#+id/lvCalibsM1"
android:layout_height="200dp" />
<TextView
android:text="Zwei Maschinen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"
android:layout_marginTop="8dp" />
<ListView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/lvCalibsM2"/>
<!-- Some more stuff here -->
</LinearLayout>
Add this to the ListView
android:scrollbars = "none"
and this in Java Code
listView.setNestedScrollingEnabled(false)
In these cases always try NestedScrollView and also add this line to it
app:layout_behavior="#string/appbar_scrolling_view_behavior"

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 :)

Setting maximum height on RecyclerView

I have a dialog fragment that contains linear layout that involves a titleText above a RecyclerView, and at the very bottom, there's a button below the recyclerView.
Since a recyclerView expands or collapses based on the number of items the adapter sets, the button sometimes gets truncated and no longer appears to be on screen, since the recyclerView just covers the entire screen.
My question is, is there a way to set the maximum height of the recyclerView without ever hiding the button underneath. I also don't want to just give the view a random height just in case the recyclerView contains no items, and it would just be a blank section.
Please let me know if you've ever run into this issue, and how you resolved this. Thanks!
UPDATED
You can achieve this easily using layout weights. Here's an example:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Title"
android:textSize="21sp"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="30dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Submit"/>
</FrameLayout>
The Title and RecyclerView will wrap content according to contents and button will always take up bottom place.
I suggest using RelativeLayout as it handles the positioning of views for cases like yours, so that you can actually focus on main design.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Some title" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/title"
android:layout_above="#+id/button"/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:gravity="center"/>
</RelativeLayout>
Above XML code is the skeleton code for what you need. you can add margins and dimensions to control the spacing. But in any case (until you provide negative margins) your views will never overlap each other.
Main trick of using RelativeLayout is the ability to use XML tags like
android:layout_below or android:layout_above or android:layout_start
or android:layout_end which perfectly aligns your view the way you
want.

How to Prevent Scrolling within FrameLayouts and Instead Have the Parent LinearLayout Handle all Scrolling?

I have a scrollable LinearLayout parent with a few FrameLayouts nested inside it as follows:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical"
android:orientation="vertical">
<FrameLayout
android:id="#+id/hb_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/gn_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/yt_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
I would like FrameLayouts to take up the space they need, allowing for scrolling of the full view through the LinearLayout.
Issue is: the LinearLayout will only take up the screen, it won't scroll, instead the FrameLayout's will scroll if the content overflows the bottom of the screen.
To be clear, I just want the FrameLayouts to fill whatever space they need, and the LinearLayout can scroll it like one long view. Must I fix the FrameLayout heights to achieve this? If so, is there risk of my layout breaking on different screen sizes/densities (or does DP really work in all cases?).
Thank you immensely!
EDIT: I have confirmed that setting fixed heights in the FrameLayout does exactly what I want this to do: scroll as one. However, why doesn't wrap_content measure the height and then go from there? That is what I expected the case was... I'm not certain how to judge the right heights for each element.
Try adding a scrollview to the layout
<?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="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical">
<FrameLayout
android:id="#+id/hb_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/gn_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/yt_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>

Layout changes animations Android

I have a RelativeLayout which has a nested empty FrameLayout and a ListView below the FrameLayout. I am adding a view to the FrameLayout with animation (setting android:animateLayoutChanges="true" in xml) and I am doing this because I want it to appear at the top of my window. So it appears with the default fade in animation. The ListView on the other hand moves down, but it is not animated. What can I do for the ListView to slide down to its position, because this is not very good looking. If I have to change the way I define my views in the layout, that's ok also. I will consider every suggestion. Thx
Here is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="#+id/frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"></FrameLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/frame"
/>
</RelativeLayout>

Categories

Resources