coordinatorlayout can not see framelayout frequently - android

this is my xml layout tree:
when i open app,and everything is well! i can scroll the page to show/hide titlebar or footerbar,but when i do something like remove all views in framelayout,and add some others view into framelayout, the framelayout just gone!
webFrameLayout.removeAllViews();
webFrameLayout.addView(newView);
i had try to handle it,but i can't. i can't see the framelayout in uiautomatorviewer.
and i had make some breakpoint in coordinatorlayout.
when onlayout() method called:coordinatorlayout has 3 child.but in uiautomatorviewer tree,i just see 2 child!
framelayout is gone.any one can help me?
my xml is :
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinator"
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.support.design.widget.AppBarLayout
android:id="#+id/bottom_tool"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:background="#FEFEFE"
android:orientation="vertical"
app:layout_behavior="inno.video.downloader.videodownloader.view.FooterBehaviorDependAppBar"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/iv_home"
style="#style/BrowserBottomToolItem"
app:srcCompat="#drawable/v_home"
/>
<FrameLayout
android:id="#+id/tab_count"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<TextView
android:id="#+id/tv_tab_count"
android:layout_width="#dimen/tab_item_text_size"
android:layout_height="#dimen/tab_item_text_size"
android:layout_gravity="center"
android:background="#drawable/tab_background"
android:contentDescription="#null"
android:gravity="center"
android:text="1"
android:textColor="#color/icon_gray"
android:textSize="12dp"
/>
</FrameLayout>
<ImageView
android:id="#+id/iv_bookmarks"
style="#style/BrowserBottomToolItem"
app:srcCompat="#drawable/v_bookmark_border"
/>
<ImageView
android:id="#+id/iv_more"
style="#style/BrowserBottomToolItem"
app:srcCompat="#drawable/v_more_vert"
/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="#dimen/search_bar_height"
android:background="#color/colorPrimary"
android:orientation="vertical"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_scrollFlags="scroll|enterAlways">
<include layout="#layout/search_bar"/>
<include layout="#layout/search_bar_page_search"/>
<Button
android:id="#+id/main_relayout_ok"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:text="#string/main_relayout_ok"
android:textColor="#color/white"
android:textSize="#dimen/text_size_16sp"
android:visibility="gone">
</Button>
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<!--web layout-->
<!--this framelayout is gone when i add/remove views-->
<FrameLayout
android:id="#+id/web_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</FrameLayout>

Related

Why occur View can not be anchored to the the parent CoordinatorLayout on android?

I want use CoordinatorLayout
but occur
IllegalStateException : View can not be anchored to the the parent CoordinatorLayout
first I add compile 'com.android.support:design:25.0.1' on gradle.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent">
<!--<include layout="#layout/base_toolbar"/>-->
<android.support.design.widget.CoordinatorLayout
android:id="#+id/myCoordinatorLayout"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent"
>
<LinearLayout
android:id="#+id/toDoEmptyView"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="#drawable/main_memo"
android:layout_width="100dp"
android:layout_height="100dp" />
<TextView
android:text="#string/main_text"
android:textColor="#color/secondary_text"
android:textSize="16sp"
android:paddingTop="4dp"
android:paddingBottom="8dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:elevation="0dp"
>
<include layout="#layout/base_toolbar"/>
</android.support.design.widget.AppBarLayout>
<!--<include layout="#layout/base_toolbar"/>-->
<!--</android.support.design.widget.AppBarLayout>-->
<hyunwook.co.kr.memoalarm.RecyclerViewEmptySupport
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/toDoRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.FloatingActionButton
android:src="#drawable/add_floating"
android:id="#+id/addToDoItemFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_anchor="#id/myCoordinatorLayout"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="hyunwook.co.kr.memoalarm.ScrollingFABBehaviour"
/>
</android.support.design.widget.CoordinatorLayout>
Why occur IllegalStateException ?
thanks.
Use parent Layout as CoordinatorLayout not a LinearLayout. and put your whole code inside CoordinatorLayout

How to use RecyclerView inside NestedScrollView

I have this layout:
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<--There is some layouts here-->
<RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
It works well. I can scroll RecyclerView smoothly without scrolling parent view.
Now I have to put the RecyclerView inside a FrameLayout like this:
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<--There is some layouts here-->
<FrameLayout
android:id="#+id/review_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include
android:id="#+id/empty_view"
layout="#layout/review_empty_view"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Now I cannot scroll the RecyclerView smoothly.
All I want is: scroll RecyclerView smoothly without scrolling parent view. What should I do?
EDIT: Here is my review_empty layout:
<?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="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/shopping_review_empty" />
<android.support.v4.widget.Space
android:layout_width="32dp"
android:layout_height="0dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/shopping_no_review_message" />
</LinearLayout>
just enable nestedscrolling that will enable smooth scrollview.
RecyclerView v = (RecyclerView) findViewById(...);
v.setNestedScrollingEnabled(false);
Use this in your recyclerView
app:layout_behavior="#string/appbar_scrolling_view_behavior"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="#+id/review_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
<include
android:id="#+id/empty_view"
layout="#layout/review_empty_view"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
Try this...
I am suggesting you to do like this. When you get Empty Data then just set Recycler View Visibility as Gone and set Empty View Visibility as Visible.
Here is Code :
<android.support.design.widget.CoordinatorLayout 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:background="#color/white"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#color/bg"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
app:layout_collapseMode="parallax">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_30dp">
<include layout="#layout/image_loading_progress" />
<com.thenakedconvos.stories.utils.CircularImageView
android:id="#+id/ivProfile"
android:layout_width="#dimen/scale_90dp"
android:layout_height="#dimen/scale_90dp"
android:transitionName="#string/transition_image" />
</FrameLayout>
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_15dp"
android:textColor="#color/black"
android:textSize="16sp"
android:transitionName="#string/transition_text"
app:typeface="gotham_medium" />
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvHoots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_5dp"
android:textColor="#color/text_color"
android:textSize="12sp"
app:typeface="gotham_book" />
<com.vanniktech.emoji.EmojiTextView
android:id="#+id/tvSmiley"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_10dp"
android:textIsSelectable="true"
app:emojiSize="25sp" />
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvAddFriend"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_15dp"
android:background="#drawable/red_rect_box"
android:gravity="center"
android:paddingBottom="#dimen/scale_12dp"
android:paddingTop="#dimen/scale_12dp"
android:text="Add"
android:textColor="#color/red"
android:textSize="14sp" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:theme="#style/AppTheme">
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/text_color"
android:textSize="18sp"
app:typeface="bariol_bold" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/scale_15dp"
android:background="#color/white"
android:orientation="vertical"
android:padding="#dimen/scale_16dp">
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvUserStory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amy N. Johnson's Stories"
android:textColor="#color/black"
android:textSize="15sp"
app:typeface="bariol_bold" />
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvTotalStories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_5dp"
android:text="110 Stories"
android:textColor="#color/text_color"
android:textSize="13sp"
app:typeface="bariol_bold" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_10dp"
android:clipToPadding="false"
android:paddingTop="#dimen/scale_10dp" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
That may be a chance you loading images(static) in to ImageView can be slow your recyclerView.
Or Big size of image.
Try to run application on mobile have good size of RAM
Add fillViewport is true in NestedScrollView in xml file as below:
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
And In your activity setNested scrolling false as below code
recycler_view.setNestedScrollingEnabled(false);
Just put your "not scrollable" layout outside the nested scroll view
All you have to do is use below line in your activity class:
ViewCompat.setNestedScrollingEnabled(recycler_view, false);
its compatible for lower versions also. and if you want to give compatible to API >21 only then use;
recycler_view.setNestedScrollingEnabled(false);

Not able to Collapse/Expand the View in Appbarlayout

I am using Appbarlayout followed by cordinatorlayout with a RecyclerView to just collapse/expand a simple TextView. But still don't know whats I am doing wrong there. The TextView(textViewMainTop) still not collapsing/expanding .Not able to findout the issue. Please have a look on my
xml code.
<?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"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="7"
android:orientation="vertical" >
<!-- <LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3.5" > -->
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3.5">
<com.openskylabs.skymo.components.TypefacedTextView
android:id="#+id/textViewMainTop"
style="#style/custom_roboto_midium"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bubbled_textview"
android:gravity="center"
app:layout_scrollFlags="scroll|enterAlways"
android:text="Good evening, Eric"
android:textSize="17dp" />
</android.support.design.widget.AppBarLayout>
<!-- </LinearLayout> -->
<LinearLayout
android:id="#+id/llTabLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="6.5"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/llFirstFavTab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_fev_small" />
<com.openskylabs.skymo.components.TypefacedTextView
style="#style/custom_roboto_midium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:text="Set Fav" />
</LinearLayout>
<View
android:id="#+id/viewVertical"
android:layout_width="0.5sp"
android:layout_height="match_parent"
android:background="#60000000" />
<LinearLayout
android:id="#+id/llSecondInviteTab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_cont_small" />
<com.openskylabs.skymo.components.TypefacedTextView
style="#style/custom_roboto_midium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:text="Invite" />
</LinearLayout>
</LinearLayout>
<View
android:id="#+id/viewBelowRay"
android:layout_width="match_parent"
android:layout_height="1sp"
android:background="#60000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#eaeaea"
android:gravity="center"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="#+id/rvOrderList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Here I want to collapse the first part. In in second part I am using RecyclerView.
You should use CollapsingToolbarLayout with AppBarLayout to collapse the widgets you want. Your Text View goes inside CollapsingToolbarLayout.
Like this.
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

Toolbar overlaps LinearLayout

I have a LinearLayout with 2 inner LinearLayouts. If I add the Toolbar in this layout-file it always overlaps the whole layout. So only the Toolbar is visible. In the other layout-files it worked without any problem.
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="de.dk.mafi.ActMain">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:padding="2dp"
app:titleMarginStart="20dp"
app:titleTextAppearance="#style/MyMaterialTheme.Base.TitleTextStyle"
app:titleTextColor="#color/textColorPrimary">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TEST"
android:textColor="#android:color/white"
android:textStyle="bold|italic"/>
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/border"
android:padding="10dp"
android:text="#string/welcome"/>
<Button android:id="#+id/button2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Favoriten"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/training"/>
<Button android:id="#+id/button" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Hauptmenü"/>
</LinearLayout>
What is the problem here?
The first LinearLayout has a wrong orientation. It should be set with vertical, instead of horizontal which gives the other children (as the inner LinearLayouts) to be draw after the Toolbar on the right outside the width screen. Change to:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
Then, remove the android:fitsSystemWindows="true" from the Toolbar.
EDIT:
I just did this, it works as expected:
<LinearLayout 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"
android:orientation="vertical"
android:fitsSystemWindows="true"
tools:context="...">
<include layout="#layout/include_toolbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/blue"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/red"/>
</LinearLayout>
Where I'm reusing this Toolbar layout on other Activities:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
Output:
My test contains above/below inner children, but to keep your requirements, juste add a parent container for the children, easily do as:
<LinearLayout ...>
<include layout="#layout/include_toolbar" />
<!-- use a parent container with horizontal orientation -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" .../>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" .../>
</LinearLayout>
</LinearLayout>

Add Footer to CoordinatorLayout

I want to add a Footer to CoordinatorLayout which contains a TabView + ViewPager.
Here is the main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.entree.entree.activity.StoreActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/black"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_tray"
android:layout_gravity="right"
android:layout_marginRight="15dp"
android:scaleType="centerInside"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_find"
android:layout_gravity="right"
android:scaleType="centerInside"
android:layout_marginRight="10dp"
/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:background="#android:color/white"
app:tabIndicatorColor="#00000000"
style="#style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_above="#+id/llTray" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:visibility="gone"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_search"
app:menu="#menu/activity_search_drawer" />
</android.support.v4.widget.DrawerLayout>
And here is the Xml Content:
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/container"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.entree.entree.activity.StoreActivity$PlaceholderFragment">
<GridView
android:id="#+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:numColumns="1"
android:stretchMode="columnWidth">
</GridView>
<LinearLayout
android:id="#+id/llTray"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
android:visibility="gone"
android:gravity="center_vertical"
android:layout_centerVertical="true"
android:background="#color/divider"
android:layout_alignParentBottom="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_gravity="left"
android:gravity="left"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/btnTray"
android:src="#drawable/ic_action_tray_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_horizontal|center_vertical"
android:layout_weight="1"
android:text="#string/view_tray" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:layout_marginRight="10dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvTotalPrice"
android:layout_width="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:text="#string/Rs"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
The footer is in xml content.
If i remove:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
in the main Xml View Pager, footer appears , else it's not shown.
How can i get the footer visible?
You already have:
<GridView
android:id="#+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:numColumns="1"
android:stretchMode="columnWidth" />
With match_parent for both height and width which it doesn't seems to be good.
Also, Perhaps you will need to show that ViewPager with NestedScrollView for scrolling the content in future.(needs a trick, but you can achieve this).
So, my suggest is, you should be able to show that footer all the time in the below of that ViewPager by adding it like this:
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_above="#+id/llTray" />
<!-- Footer aligned to bottom -->
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FC0"
android:gravity="center"
app:layout_anchor="#id/main_content"
app:layout_anchorGravity="bottom">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Fixed Footer"
android:textColor="#000"
android:textSize="20sp" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
This should show the footer all the time (even when ViewPager is collapsing).
Or if you want to show it in your ViewPager:
you should add this in your contents:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
Which means, it will put the contents below the AppbarLayout
Anyways, your contents problem is coming from that GridView like i said, it will match all the content and you don't have ScrollView or even NestedScrollView to show the other contents.

Categories

Resources