I can't get any way to hide the TabLayout when I scroll a fragment
I tried app:layout_scrollFlags="scroll|enterAlways" but no results
I put appbarlayout, collapsedBarLayout too but not hide anything
Right now I have this code:
<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"
>
<LinearLayout
android:id="#+id/header"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/blanco"
>
<FrameLayout
android:id="#+id/tab"
android:layout_width="match_parent"
android:layout_height="48dp"
/>
<FrameLayout
android:id="#+id/subtab"
android:layout_width="match_parent"
android:layout_height="48dp"
android:visibility="gone"
/>
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="#+id/viewpagertabb"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="5dp"
android:background="#drawable/tab_layout_background"
app:tabMode="scrollable"
app:layout_scrollFlags="scroll|enterAlways"
app:tabIndicator="#drawable/tab_background_selected"
/>
<android.support.design.widget.TabLayout
android:id="#+id/viewpagertabsub"
android:layout_width="match_parent"
android:layout_height="48dp"
android:visibility="gone"
android:background="#drawable/sub_tab_layout_background"
app:tabMode="scrollable"
app:layout_scrollFlags="scroll|enterAlways"
app:tabBackground="#drawable/sub_tab_layout_selector"
app:tabSelectedTextColor="#color/blanco"
android:layout_below="#id/viewpagertabb"
/>
<FrameLayout
android:id="#+id/viewpagerpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/viewpagertabsub"
/>
</RelativeLayout>
In the last FrameLayout is where is the content of a fragment. Anyone?
Thank to all!
Related
I am trying show fab more button inside the nested scroll view.I have searched for many solutions but not found any solution which I can able to show fab more button in right bottom
<?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="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageButton
android:id="#+id/bt_close"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="#android:color/white"
app:srcCompat="#drawable/ic_close" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="Filter All Order"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Title"
android:textColor="#android:color/white" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:scrollingCache="true">
<LinearLayout
android:id="#+id/billBlock"
android:layout_width="match_parent"
android:layout_height="match_parent">
//many inner layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#color/grey_10" />
<android.support.v7.widget.RecyclerView
android:id="#+id/print_payment_list"
android:layout_margin="10dp"
android:background="#color/grey_20"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="#+id/fabFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_mic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_middle"
android:clickable="true"
android:tint="#color/grey_80"
app:backgroundTint="#color/grey_20"
app:fabSize="mini"
app:rippleColor="#android:color/white"
app:srcCompat="#drawable/ic_mic" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_middle"
android:clickable="true"
android:tint="#color/grey_80"
app:backgroundTint="#color/grey_20"
app:fabSize="mini"
app:rippleColor="#android:color/white"
app:srcCompat="#drawable/ic_photo_camera" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/spacing_smlarge"
android:layout_marginLeft="#dimen/spacing_smlarge"
android:layout_marginRight="#dimen/spacing_smlarge"
android:layout_marginTop="#dimen/spacing_middle"
android:clickable="true"
android:tint="#android:color/white"
app:fabSize="normal"
app:rippleColor="#android:color/white"
app:srcCompat="#drawable/ic_add" />
<!--android:src="#drawable/ic_close_black_24dp"-->
</FrameLayout>
</LinearLayout>
I have multiple views inside one parent of nested scroll view .scroll and all working fine .only issue is fab is not positioned in a bottom right position
can anyone help me how I can achieve this? since am new to android.T hanks
i need fab bar to be placed like this .This is sample image from google
try this one
<?xml version="1.0" encoding="utf-8"?>
<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:background="#android:color/white"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/app"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageButton
android:id="#+id/bt_close"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="#android:color/white"
app:srcCompat="#drawable/ic_close" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="Filter All Order"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Title"
android:textColor="#android:color/white" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_below="#id/app"
android:layout_above="#+id/fabFrame"
android:layout_height="match_parent"
android:scrollbars="none"
android:scrollingCache="true">
<LinearLayout
android:id="#+id/billBlock"
android:layout_width="match_parent"
android:layout_height="match_parent">
//many inner layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#color/grey_10" />
<android.support.v7.widget.RecyclerView
android:id="#+id/print_payment_list"
android:layout_margin="10dp"
android:background="#color/grey_20"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<FrameLayout
android:id="#+id/fabFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="?attr/actionBarSize"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_mic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_middle"
android:clickable="true"
android:tint="#color/grey_80"
app:backgroundTint="#color/grey_20"
app:fabSize="mini"
app:rippleColor="#android:color/white"
app:srcCompat="#drawable/ic_mic" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_middle"
android:clickable="true"
android:tint="#color/grey_80"
app:backgroundTint="#color/grey_20"
app:fabSize="mini"
app:rippleColor="#android:color/white"
app:srcCompat="#drawable/ic_photo_camera" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/spacing_smlarge"
android:layout_marginLeft="#dimen/spacing_smlarge"
android:layout_marginRight="#dimen/spacing_smlarge"
android:layout_marginTop="#dimen/spacing_middle"
android:clickable="true"
android:tint="#android:color/white"
app:fabSize="normal"
app:rippleColor="#android:color/white"
app:srcCompat="#drawable/ic_add" />
<!--android:src="#drawable/ic_close_black_24dp"-->
</FrameLayout>
</RelativeLayout>
Always used linear layout for continuous Views and use Framelayout or Relative Layout when you what to show something position like right or bottom.
In my CountryActivityInfo.java I have a collapsing toolbar with both width and height set to match-parent so it can occupy the whole phone screen. When I scroll up the toolbar gets a fixed 200dp height.
Right now, it looks like this:
I want to display, in that white screen that appears when the toolbar is collapsed, a vertical scroll view with a text view inside. How can I do that? I've tried this way:
<android.support.design.widget.AppBarLayout
android:id="#+id/testeparainfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/actionBarDivider">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/backgroundcollapsedtoolbarinfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="exitUntilCollapsed|scroll">
<ImageView
android:id="#+id/imgCountryInfoFoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<ImageView
android:id="#+id/imgCountryInfoEscuro"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="#drawable/background_pais_info"
android:scaleType="centerInside" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbaridinfo"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
<TextView
android:id="#+id/txtNomePaisInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="30dp"
android:layout_marginTop="520dp"
android:paddingBottom="10dp"
android:text="TextView"
android:textColor="#android:color/background_light"
android:textSize="35sp"
app:layout_anchor="#+id/testeparainfo"
app:layout_anchorGravity="left|bottom" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txtInfoPais"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/btnArrowBackWhite"
android:layout_marginBottom="111dp"
android:text="TextView"
android:textColor="#android:color/background_light"
android:textSize="15sp"
android:visibility="invisible"
app:layout_anchor="#+id/imgCountryInfoFoto"
app:layout_anchorGravity="bottom|center" />
</LinearLayout>
</ScrollView>
But, when I do this, the text view gets inside the collapsing toolbar and gets collapsed with the toolbar.
By the way, all the XML is wrapped up in a Coordinator Layout!!!
Change the root to CoordinatorLayout
<?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"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_scrolling" />
</android.support.design.widget.CoordinatorLayout>
and then in content_scrolling.xml use NestedScrollView and app:layout_behavior="#string/appbar_scrolling_view_behavior" use this property for proper behaviour.
<android.support.v4.widget.NestedScrollView 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="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
...
</android.support.v4.widget.NestedScrollView>
Add app:layout_behavior="#string/appbar_scrolling_view_behavior" inside your ScrollView.
Replace this code
you have to add app:layout_behavior="#string/appbar_scrolling_view_behavior" in your ScrollView.
<ScrollView
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txtInfoPais"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/btnArrowBackWhite"
android:layout_marginBottom="111dp"
android:text="TextView"
android:textColor="#android:color/background_light"
android:textSize="15sp"
android:visibility="invisible"
app:layout_anchor="#+id/imgCountryInfoFoto"
app:layout_anchorGravity="bottom|center" />
</LinearLayout>
</ScrollView>
I am working with AndroidStudio 3.0 and I am creating a TabbedActivity with Fragments using Java.
For realizing the following design:
sketch
i sourrounded the ViewPager with a RelativeLayout in order to display a static content object (TextView) below the ViewPager. For this I am using the attribute
android:layout_below="#id/container"
Unfortunately, the TextView never gets shown.
By fuzzling around i realized, that when setting the
android:layout_height="100dp"
of the ViewPager to a fixed value it will be displayed.
As I am a beginner to Android I am unsure how to handle this issue. Is it not possible to use the layout_below attribute when working with ViewPagers? Or do i have to set a fixed value for them?
Is there another solution to achieve what i want - simply showing a static content below a 'TabControl'?
Here is my complete 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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<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:layout_weight="1"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:title="#string/app_name">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabItem
android:id="#+id/tabItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tab_text_1" />
<android.support.design.widget.TabItem
android:id="#+id/tabItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tab_text_2" />
<android.support.design.widget.TabItem
android:id="#+id/tabItem3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tab_text_3" />
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" >
</android.support.v4.view.ViewPager>
<TextView
android:id="#+id/static_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="This is the Textiew that is not shown!"
android:layout_below="#id/container"
/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Thank You very much!
Change this part of your code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" >
</android.support.v4.view.ViewPager>
<TextView
android:id="#+id/static_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="This is the Textiew that is not shown!"
android:layout_below="#id/container"
/>
</RelativeLayout>
I would replace this with a vertical LinearLayout. This allows you to give some space to the TextView and then give the rest of the space to the ViewPager, which a RelativeLayout won't allow.
<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:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
<TextView
android:id="#+id/static_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="This is the Textiew that is not shown!"/>
</LinearLayout>
I am using viewpager to show different fragments but in this one of fragment replaces the actionbar. Till now I have found that it is because of edittext which I am using for searching items. When I remove edittext from this it works fine.
The main activity layout is a CoordinatorLayout, containing the typical AppBarLayout and then a ViewPager and it is filling whole screen.
fragment_gst_rates.xml:
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="5dp"
tools:context="com.kamalarora.mygst.FragmentGstRates">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linearLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/searchBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search items . . ."
android:layout_marginTop="5dp"
android:layout_marginBottom="2dp"
android:drawableRight="#android:drawable/ic_menu_search"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/lightGrey">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Products"
android:textSize="18dp"
android:layout_marginLeft="1dp"
android:padding="5dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="GST Rate"
android:layout_marginRight="1dp"
android:textSize="18dp"
android:gravity="right"
android:padding="3dp"/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/listView">
</ListView>
</LinearLayout>
</LinearLayout>
activity_main.xml:
<?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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.kamalarora.mygst.MainActivity">
<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="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<View
android:id="#+id/appbar_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/transparent"
android:visibility="invisible" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="104dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottomNav"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
app:itemBackground="#color/white"
app:itemIconTint="#color/mediumgrey"
app:itemTextColor="#color/mediumgrey"
app:menu="#menu/menu_bottom" />
<!--<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" /> -->
</android.support.design.widget.CoordinatorLayout>
do you tried with the linear layout at the root there try change with android:layout_height="wrap_content" .
I'm developing an app that has a Main Activity and a Navigation Drawer to switch between different fragments inside the Main Activity.
One of the fragments contains a tab layout.
My layouts are a mess and they don't behave or perform properly.
Here is my XML:
Main:
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true"
android:clickable="true"
android:layoutDirection="rtl"
android:id="#+id/drawer_layout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="rtl"
android:background="#EEEEEE"
android:clickable="true">
<include
android:id="#+id/toolbar"
android:gravity="right"
layout="#layout/toolbar"
android:clickable="true" />
<FrameLayout
android:id="#+id/content_frame"
android:layout_below="#id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/mainFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_gravity="bottom|end"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:layout_marginTop="5dp"
android:elevation="8dp"
app:pressedTranslationZ="12dp"
app:backgroundTint="?android:colorAccent"
android:src="#drawable/ic_perm_phone_msg_white_24px" />
<LinearLayout
android:id="#+id/miniFabFrame"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_alignParentLeft="true"
android:layout_gravity="bottom|end"
android:layout_marginLeft="20dp"
android:layout_above="#id/mainFab"
android:padding="0dp">
<android.support.design.widget.FloatingActionButton
android:id="#+id/messageFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:elevation="8dp"
android:layout_marginTop="5dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
app:pressedTranslationZ="12dp"
app:backgroundTint="?android:colorPrimary"
app:fabSize="mini"
android:src="#drawable/ic_textSMS_white_24px" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/callFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:elevation="8dp"
app:pressedTranslationZ="12dp"
app:backgroundTint="?android:colorPrimary"
app:fabSize="mini"
android:src="#drawable/ic_call_white_24px" />
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:id="#+id/nav_view"
android:layoutDirection="rtl"
app:headerLayout="#layout/header"
app:menu="#menu/nav_menu" />
</android.support.v4.widget.DrawerLayout>
Tabs Fragment:
<LinearLayout 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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:id="#+id/halachot_layout"
android:layoutDirection="ltr">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.refractored.PagerSlidingTabStrip
android:id="#+id/halachotTabs"
android:layout_below="#id/halachot_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
pstsPaddingMiddle="false"
app:pstsShouldExpand="true" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/halachotPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
I want to use Coordinator Layout in my Main layout, and use AppBarLayout to wrap the Toolbar, although I don't know how to use them.
If someone could please help me organize my layout properly, with some explanations of how this works and what I am doing wrong, I would appreciate it very very much.
Thanks!
Firstly create an activity layout which contains Navigation Drawer and ToolBar
<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.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:background="#drawable/ab_bg2"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="#style/Base.TextAppearance.AppCompat.Subhead"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginBottom="40dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:contentInsetStart="0dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginRight="3dp"
android:layout_marginTop="5dp"
android:background="#drawable/linlayoutshape_shadow"
android:tag="#string/layout_default"/>
</android.support.design.widget.CoordinatorLayout>
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#color/Drawer_bg"
android:choiceMode="singleChoice"
android:divider="#color/Drawer_bg"
android:dividerHeight="10dp"
android:listSelector="#drawable/list_selector"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" />
Now create a Fragment which will show your Tab layout
<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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.utils.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#drawable/background_tab"
app:pstsShouldExpand="true" />
<com.utils.CustomViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linHeader"
android:background="#drawable/background_tab"
tools:context=".TestBoardActivity" />
</RelativeLayout>