Correct hierarchy for SlidingUpPanelLayout, SwipeRefreshLayout, and RecyclerView - android

I just started playing with com.sothree.slidinguppanel.SlidingUpPanelLayout in the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.rburgosnavas.droidfs.MainActivityFragment"
android:id="#+id/main_list_rec"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar_main"/>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoParalaxOffset="100dp"
sothree:umanoDragView="#+id/dragView"
sothree:umanoOverlay="true"
sothree:umanoScrollableView="#+id/swipe_refresh_rec"
>
<!-- Main content -->
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_rec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<!-- Draggable view -->
<LinearLayout
android:id="#+id/dragView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bright_foreground_material_dark"
android:orientation="vertical"
android:clickable="true"
android:focusable="false">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="LOL-LOL-LOL-LOL-LOL"
/>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</LinearLayout>
The issue I'm facing is that the RecyclerView doesn't always respond to scroll events, and I'm starting to think that my layout hierarchy may be wrong. I haven't done anything on the Java side with SlidingUpPanelLayout as I just wanted to start simply, and I don't think that's an issue.
Does any have any pointers?

Related

(Android Layout) How to custom a View that can simply contains other View?

For example, I have a activity and it's layout xml file likes this:
<?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:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="#+id/card1"
android:layout_width="match_parent"
android:layout_height="64dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- something1 -->
</LinearLayout>
</ScrollView>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card2"
android:layout_width="match_parent"
android:layout_height="64dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- something2 -->
</LinearLayout>
</ScrollView>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card3"
android:layout_width="match_parent"
android:layout_height="64dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- something3 -->
</LinearLayout>
</ScrollView>
</androidx.cardview.widget.CardView>
</LinearLayout>
This is only used to express my problem and not the real layout used in my production environment. Each "something" refers to the specific layout and they are so different that I can't use ListView or RecyclerView.
As you can see, each "something" has similar CardView, ScrollView and LinearLayout, so I wonder if it is possible to make them as a custom view that I could simplify my layout as the following codes?
<?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:orientation="vertical">
<com.example.myapplication.myCustomContainer
android:id="#+id/something1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- something1 -->
</com.example.myapplication.myCustomContainer>
<com.example.myapplication.myCustomContainer
android:id="#+id/something2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- something2 -->
</com.example.myapplication.myCustomContainer>
<com.example.myapplication.myCustomContainer
android:id="#+id/something3"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- something3 -->
</com.example.myapplication.myCustomContainer>
</LinearLayout>
Thanks in advance!
You can make use of , and set each of your Views in his layout, as needed, but for that, you would need to create an xml item for each one of them.
Example:
<include
android:id="#+id/ic_something1"
layout="#layout/something1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include
android:id="#+id/ic_something2"
layout="#layout/something2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="#+id/ic_something3"
layout="#layout/something3"
android:layout_width="match_parent"
android:layout_height="match_parent" />

ListView not utilizing full space in FrameLayout

I have an activity layout with 2 FrameLayout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
tools:context="de.sioned.multivoc.AddWordActivity"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<include layout="#layout/toolbar_layout"/>
<ScrollView
android:id="#+id/scLeft"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/paneLeft"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/paneLeftTop"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/paneLeftBottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/paneLeftTop"/>
</RelativeLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
The 2nd FrameLayout paneLeftBottom will at some point contain the following fragment:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/lyTop"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...some static fields...
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/lyTop">
<ListView
android:id="#+id/lvResult"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"/>
</RelativeLayout>
In this configuration the ListView is only shown with a height of one of it's rows instead several rows utilizing the available space. The ListView works fine but only one row at a time is displayed.
The same ListView fragment works fine when I put it into a 2-pane landscape layout. How can I make the ListView use the available space ?
Edit:
Found a partial solution by switching to a LinearLayout within the ScrollView. Only problem left is, that the bottom Framelayout overlays a bit of the top FrameLayout when I load the said fragment into it. But that is acceptable in this case as it is only temporary to select some data.
<ScrollView
android:id="#+id/scLeft"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:id="#+id/paneLeft"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/paneLeftTop"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/paneLeftBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</ScrollView>
This right here
android:layout_width="match_parent"
android:layout_height="match_parent"
Should be
android:layout_width="match_parent"
android:layout_height="wrap_content"

Android: How to Display included layout and listview in one view together?

I would like to ask how can i display included layout and listview positioned under the included in onde view.
Layout:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.TransactionsActivity">
<include
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_alignParentTop="true"
layout="#layout/preloader" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/list"
/>
</android.support.v4.widget.SwipeRefreshLayout>
In the preview is displayed only the included layout, but lisview below is not displayed.
Many thanks for any advice.
Since SwipeRefreshLayout accept only one child. Wrap it inside LinearLayout or RelativeLayout.
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.TransactionsActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
layout="#layout/preloader"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_alignParentTop="true" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Best Of Luck.

the RecyclerView I am injecting does not appear?

Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal">
<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:dividerHeight="10dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/content_main">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"></include>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerView"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#ffffff"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<android.support.v7.widget.RecyclerView
android:id="#+id/threadRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</RelativeLayout>
</LinearLayout>
The main reason I did this design was to try to display the
<android.support.v7.widget.RecyclerView
android:id="#+id/threadRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
properly. However, when it is not being displayed at all. Before adding the two relativelayouts, I have one relative layout and the recyclerview did display, but it match_parent for every item of the list and was not able to fix it. How can I display my view properly?
The problem probably has to do with the layout_height="wrap_content" on your RecyclerView. You need to use setAutoMeasureEnabled(true) for wrap_content to work properly with a RecyclerView.
Here's an example:
RecyclerView threadRecyclerView = (RecyclerView)findViewById(R.id.threadRecyclerView);
threadRecyclerView.getLayoutManager().setAutoMeasureEnabled(true);
And your your XML should look something like this:
<android.support.v7.widget.RecyclerView
android:id="#+id/threadRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layoutManager="LinearLayoutManager"/>
Hope that helps. :)
Note that setAutoMeasureEnabled only works properly for Android Support Library +23.2

Reusing XML in android by <include>

I am using ActionBarSherlock for tabs in android
main_fragment_desc_list_view.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/screen_parent_topbar" />
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.app.FragmentTabHost>
<include layout="#layout/screen_parent_bottombar" />
</LinearLayout>
What i am having trouble with ?
Even though i have added the code <include layout="#layout/screen_parent_bottombar" /> it is not shown in the screen when i execute the code
What changes should i need to make here so that i am able to get my bottom layout included at the bottom ?
Your android.support.v4.app.FragmentTabHost has a height of MATCH_PARENT and therefore the layout at the bottom will not appear.
One alternative would be using a RelativeLayout to create the header/content/footer layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include android:id="#+id/header"
android:layout_alignParentTop="true"
layout="#layout/screen_parent_topbar" />
<include android:id="#+id/footer"
android:layout_alignParentBottom="true"
layout="#layout/screen_parent_bottombar" />
<android.support.v4.app.FragmentTabHost
android:layout_below="#id/header"
android:layout_above="#id/footer"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.app.FragmentTabHost>
</RelativeLayout>

Categories

Resources