I don't really know how to ask this question but I will start off with the idea here.
So I have a MainFragment that contains a SlidingUpPanelLayout that includes a viewpager and a layout that hold the controls for the application.
And what I want to do is when I change between fragments in the tablayout I want to change the layout of that holds the controls, I also want to trigger functions from the fragment with the controls in on my different fragments in the viewpager.
But since they are in different fragments I don't know how to get the control layouts and buttons to change and get a hold of them.
So here is first an image of the layout:
https://imgur.com/a/SgdI21L
And here is how my following XML looks like:
XML for the Control Content:
<LinearLayout android:id="#+id/control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000"
android:clickable="false"
android:gravity="center|top"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/controlBackground"
app:tabGravity="fill"
app:tabIndicatorColor="#color/colorText"
app:tabMode="scrollable"
app:tabSelectedTextColor="#color/colorAccent"
app:tabTextColor="#color/colorText">
</android.support.design.widget.TabLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.FloatingActionButton
android:id="#+id/takePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:backgroundTint="#color/colorText"
android:clickable="true" />
<ImageButton
android:id="#+id/flipCamera"
style="#android:style/Widget.Material.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|left"
android:padding="20dp"
android:clickable="true"
android:tint="#color/colorText"
android:backgroundTint="#color/colorText"
android:src="#drawable/ic_outline_camera_front_24px" />
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/openGallery"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center|right"
android:padding="20dp"
android:src="#drawable/fox"
android:clickable="true"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp" />
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|top"
android:padding="10dp"
android:text="Pete is king!"
android:layout_gravity="center"
android:textColor="#color/colorText"
android:textSize="16sp" />
<ImageButton
android:id="#+id/info"
style="#android:style/Widget.Material.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|end"
android:layout_weight="1"
android:padding="20dp"
android:clickable="true"
android:backgroundTint="#color/colorAccent"
android:tint="#color/colorAccent"
android:src="#drawable/ic_shutterowl_24dp" />
</LinearLayout>
</LinearLayout>
And here is my viewpager:
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<owlapps.shutterowl.AutoFitTextureView
android:id="#+id/texture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/control"
xmlns:android="http://schemas.android.com/apk/res/android" />
</android.support.v4.view.ViewPager>
They are all showed together in a SlideUpPanelLayout like so:
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
sothree:layout_constraintHeight_max="80dp"
sothree:umanoPanelHeight="120dp"
sothree:umanoShadowHeight="0dp"
sothree:umanoOverlay="true">
<include layout="#layout/camera_content"/>
<include layout="#layout/control_content"/>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
I had an idea to solve this with a interface that could trigger functions from the MainFragment that loads the camera and content layouts, here is what i tried:
In a click event from the mainfragment: Tab1Fragment.take.visible(true);
My interface looks like this:
public interface CameraControlListener {
void visible(boolean status);
}
And is implemented in the Tab1Fragment that holds the camera view:
#Override
public void visible(boolean status) {
if(status){
takePicture();
}
}
So how can I get all these to speak with eachother?
As i move between fragments i want the controls to change that are inside another fragment and also trigger functions from the active tabfragment in the viewpager.
Related
For some reason, the UI of my fragments is not correctly re-rendering anymore with the new SDK. This is only the case on Android devices with Android 8.0 or higher.
When changes are made in the UI it seems that only 1 fourth of the screen is actually rerendered. So old items are still visible on the screen, and new items are only rendered in the upper left 1/4th of the screen.
When I start dragging (even just a little bit) the view readjusts and renders completely.
I have added some pictures below to demonstrate what is happening. To make it more clear, I have colored the background of the fragments red and blue, so you can see which part has rerendered. As you can see in picture 2, only a part of the fragment has rendered. In picture 3 after dragging a bit (there are multiple tabs) the fragment is completely rendered.
1 Before UI update
2 After UI update
3 After UI update and dragging
The layout for my viewpager / tablayout activity is as follows:
<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/layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"
android:fillViewport="false" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
The layout in my fragment is as follows. There are two parts. Only one is visible at a time and the other has visibility GONE. The RelativeLayout with id "step1" starts as VISIBLE and the one with "step2" starts as GONE. When pressing the button "step1" will be set to GONE and "step2" to VISIBLE.
<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"
tools:context=".depot.fragment.StockFragment">
<RelativeLayout
android:id="#+id/step1"
android:background="#color/holo_blue_dark"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kies het pand" />
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:id="#+id/radio_group">
</RadioGroup>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:id="#+id/footer">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"/>
<Button
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/button_next"
android:text="Volgende"/>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/step2"
android:background="#color/holo_red_dark"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/header_step2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="#+id/depot_choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Material.header"
android:text="Kies het pand" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Klik op de knop rechtersonderin het scherm om scannen te starten." />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tableContainer"
android:layout_below="#+id/header_step2"
android:layout_above="#+id/footer_step2">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v7.widget.RecyclerView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:elevation="6dp"
app:backgroundTint="#color/accent"
android:src="#drawable/ic_border_color_black_24dp"
android:id="#+id/floating_qrcode_manual"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/floating_qrcode_scan"
android:layout_toStartOf="#+id/floating_qrcode_scan"
android:layout_marginBottom="10dp"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:elevation="6dp"
app:backgroundTint="#color/accent"
android:src="#drawable/qrcode_scan"
android:id="#+id/floating_qrcode_scan"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:id="#+id/footer_step2">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/divider_light"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"/>
<Button
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/button_prev"
android:text="Ander pand kiezen"/>
</RelativeLayout>
</RelativeLayout>
Could anyone help me find the problem with this code?
I finally managed to track down the problem.
It had nothing to do with the ViewPager. Only there were settings in the AndroidManifest that messed up the re-rendering of fragments after android 8.0.
The settings that caused the problems were the following:
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
Removing these solved the problems.
In my activity_navigation.xml I put my FAB here.
The is below:
<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"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content_frame">
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:menu_icon="#drawable/quick_apply"
android:layout_gravity="bottom|right"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/view_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/imgicon"
fab:fab_size="mini"
fab:fab_label="View Images" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/camicon"
fab:fab_size="mini"
fab:fab_label="Camera" />
</com.github.clans.fab.FloatingActionMenu>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/activity_navigation_drawer"
android:background="#color/tableHeader"/>
I set this xml on my NavigationActivity where this will be like my BaseActivity and then extended it to all my other Activities.
My problem when running the app the FAB is not displaying, because it has been covered by the xml I assign to the content_frame. But If I put the com.github.clans.fab.FloatingActionMenu in one of my other activities's xml for example in my Home Screen it will display it but i wonder how can I display the FAB without repeating it to add on my xml. All the action of the FAB I put it on my NavigationActivity.
Thank you for the help.
update
By the way I'm using the FrameLayout named content_frame to my other activities to display the xml of that Activity like in my Home Screen like this
FrameLayout contentFrameLayout = (FrameLayout) findViewById(R.id.content_frame);
getLayoutInflater().inflate(R.layout.activity_home, contentFrameLayout);
//i do not have your resource value, so i try to make a test example, which replace your drawer view with textview. If i put framelayout height with match parent, i only see one textview, only if i put the height be 20dp, it will appear both textviews.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="20dp"
android:id="#+id/content_frame">
<TextView
android:text="text above"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
<TextView
android:text="text below"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
What I did is I create two FrameLayout in my activity_navigation.xml
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:menu_icon="#drawable/quick_apply"
android:layout_gravity="bottom|right"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/view_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/imgicon"
fab:fab_size="mini"
fab:fab_label="View Images" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/camicon"
fab:fab_size="mini"
fab:fab_label="Camera" />
</com.github.clans.fab.FloatingActionMenu>
</FrameLayout>
Where my FAB is not inside the content_frame, so that it will not overlap.
use Fragment instant of Activity
Hey guys I am a bit new to android programming but I can't seem to get my recycle view inside my viewpager working. I am using my viewpager with a tablayout and inside one of the pages, I have a recyclerview which contains cardviews with dynamically created content inside each of them (each card view will have different heights based on the content inside). The issue I am having right now is that my recycleriew's height only extends to the height of the viewpager even tho sometimes the cardview inside my recyclerview has too much content to fit on the viewpager screen.
As you can see from the picture, my cardview has taken up the whole screen but I have a few more exercises in my exercise list that I used to created the cardview and they are cut off..
Below is my xml for the activity that contains my view pager, the xml for the viewpager fragment, and also the xml for my cardview
Activity with my viewpager
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/view"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/view">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
viewpager fragment with the recyclerview
<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"
tools:context="com.example.davidyuan7536.workoutlog.LogFragment"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/homeFeedRecycleView" />
</LinearLayout>
cardview inside the recyclerview
<?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:padding="16dp"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cv"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="#color/homeFeedUserHeaderBackground">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="#+id/homeFeedUserAvatar"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp"
android:src="#drawable/profile_icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/homeFeedUserName"
android:layout_toRightOf="#+id/homeFeedUserAvatar"
android:layout_alignParentTop="true"
android:textSize="20sp"
android:text="User Name"
android:singleLine="true"
android:ellipsize="end"
android:layout_marginRight="10dp"
android:textColor="#color/textColorPrimary"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/homeFeedWorkoutTitle"
android:layout_toRightOf="#+id/homeFeedUserAvatar"
android:layout_below="#+id/homeFeedUserName"
android:text="Workout Titile"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:textSize="15sp"
android:textColor="#color/textColorPrimary"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/homeFeedExercisesContainer"
android:paddingBottom="10dp">
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Eliminate the outer LinearLayout surrounding the CardView.
It has android:layout_height="match_parent" which is causing your problem, and it only has the CardView as a child, so it's not necessary anyways.
I am using CollapsingBarLayout with viewpager and the fragments of viewpager are having listview, gridview.
Here is my 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"
tools:context="com.bigsteptech.seandroidnativeapp.classes.modules.common.ViewGroupEvent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="#style/TransparentText">
<FrameLayout
android:id="#+id/carouselLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax">
<ImageView
android:id="#+id/coverImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="bottom"
android:orientation="vertical"
android:layout_gravity="bottom"
android:padding="#dimen/profile_image_margin"
android:background="#drawable/gradient_bg"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/profile_image_margin"
android:textSize="#dimen/text_size_xlarge"
android:textStyle="bold"
android:textColor="#color/white"
android:id="#+id/content_title"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginLeft="#dimen/profile_image_margin"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="#dimen/text_size_medium"
android:id="#+id/category_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_toRightOf="#+id/category_title"
android:layout_marginLeft="#dimen/profile_image_margin"
android:textColor="#color/white"
android:textSize="#dimen/text_size_medium"
android:id="#+id/memberCount"/>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="#style/ActionBarThemeOverlay"
app:popupTheme="#style/ActionBarPopupThemeOverlay"
android:background="#drawable/gradient_bg"
app:layout_collapseMode="pin" />
</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:layout_gravity="fill_vertical"
android:isScrollContainer="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contentInfo"
android:paddingBottom="48sp"
android:clipToPadding="false"
android:orientation="vertical">
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/profile_page_left_right_margin"
android:layout_gravity="center"
android:id="#+id/progressBar"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="#color/grey_light">
<TextView android:id="#+id/ownerTitle"
android:clickable="true"
android:focusable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/keyline_1"
android:layout_gravity="center_vertical"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/body_text_1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/profile_image_margin"
android:padding="10dp">
<com.bigsteptech.seandroidnativeapp.Classes.Modules.Common.ViewRelated.ExpandableTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/keyline_1"
style="#style/TextBody"
android:layout_gravity="center_vertical"
android:id="#+id/view_description" />
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="#+id/slidingTabs"
android:layout_width="match_parent"
app:tabIndicatorHeight="3dp"
app:tabMode="scrollable"
android:layout_height="wrap_content"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="300dp">
</android.support.v4.view.ViewPager>
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="#id/appbar"
android:id="#+id/joinGroupButton"
app:layout_anchorGravity="bottom|right|end"
android:src="#drawable/ic_action_new"
android:layout_margin="#dimen/fab_margin"
android:clickable="true"/>
</android.support.design.widget.CoordinatorLayout>
The fragments which are having listview, gridview do not scroll to up in collapsing toolBar, how can I achieve this working..
Please help me, thank you so much in advanced...
You need put your ViewPager inside AppBar section and setup layout_behavior :
<android.support.design.widget.AppBarLayout>>
<android.support.design.widget.CollapsingToolbarLayout>
// THIS VIEWS WILL BE COLLAPSED
</android.support.design.widget.CollapsingToolbarLayout>
// THIS VIEWS WILL BE PINNED
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
</android.support.design.widget.AppBarLayout>
If you using Fragments as children of ViewPager you need setup layout_behavior to each fragment inside ViewPager too.
app:layout_behavior="#string/appbar_scrolling_view_behavior"
collapsing toolbar with tabs using new material design support library
I used official collapsing toolbar feature of new material design support library.
here collapsed view height is 256dp and tabs height is 56dp
i made following path
i cut image into two parts one for collapsed view and one for tabs.
i cutted images according to dp to pixel sizes with high resolution drawable xxxhdpi and put into drawable folder so it will adjustable to all screen sizes
i have 2000x1246 image
top image 256dp= 2000x1024 pixel
bottom tab image 56dp= 2000x224 pixel
Here is the complete example with source code
ListView and GridView are not equipped with NestedScrolling functions. And thats needed to work with the CollapsingToolbarLayout.
The easiest way to make it work, would be to change your ListView and GridView to RecyclerViews (RecyclerView implements NestedScrollingChild).
i have achieved this i will put my code with the library used
firstly this is the layout file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/attraction_lay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f5f6f5">
<RelativeLayout
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="47dp">
<TextView
android:id="#+id/exp_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:text="See & do"
android:textColor="#1b7bba"
android:textSize="17sp" />
<RelativeLayout
android:id="#+id/relmenu"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<ImageView
android:layout_width="17dp"
android:layout_height="14dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="17dp"
android:layout_marginLeft="8dp"
android:src="#drawable/menu_icon_blue" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relsearch"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true">
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="17dp"
android:layout_marginRight="8dp"
android:src="#drawable/search_icon_blue" />
</RelativeLayout>
</RelativeLayout>
<View
android:id="#+id/div"
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_below="#+id/bar"
android:background="#1b7bba" />
<FrameLayout
android:id="#+id/layout_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/div">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:divider="#null"
android:focusable="false"
android:focusableInTouchMode="false"
android:listSelector="#android:color/transparent"
android:scrollbars="none" />
<FrameLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="290dp"
android:layout_marginTop="0dp"
android:orientation="vertical">
<FrameLayout
android:id="#+id/images_header"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:layout_marginBottom="40dp">
<android.support.v4.view.ViewPager
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:overScrollMode="never" />
<RelativeLayout
android:id="#+id/gallery_back"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_gravity="left|center_vertical">
<ImageView
android:layout_width="20dp"
android:layout_height="52dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/arrow_back" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/gallery_next"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_gravity="right|center_vertical">
<ImageView
android:layout_width="20dp"
android:layout_height="52dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/arrow_next" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="-150dp"
android:layout_marginTop="170dp"
android:background="#drawable/horizontal_gradient" />
<TextView
android:id="#+id/pagenum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:text="3/15"
android:textColor="#FFF"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/header_text_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/min_height_textheader_materiallike"
android:layout_gravity="bottom"
android:background="#FFF">
<!--<TextView-->
<!--android:id="#+id/text_header"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center_vertical"-->
<!--android:layout_marginLeft="70dp"-->
<!--android:text="ttttt"-->
<!--android:textColor="#android:color/white"-->
<!--android:textSize="18sp"-->
<!--android:textStyle="bold" />-->
<RelativeLayout
android:id="#+id/button_header"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="83dp"
android:layout_marginRight="83dp">
<RelativeLayout
android:id="#+id/photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="2.5">
<ImageView
android:layout_width="17dp"
android:layout_height="14dp"
android:layout_centerInParent="true"
android:background="#drawable/photo_blue_icon"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5">
<ImageView
android:layout_width="14dp"
android:layout_height="16dp"
android:layout_centerInParent="true"
android:background="#drawable/video_blue_icon" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/share"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5">
<ImageView
android:layout_width="15dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:background="#drawable/share_blue_icon" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/fav"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5">
<ImageView
android:layout_width="20dp"
android:layout_height="19dp"
android:layout_centerInParent="true"
android:background="#drawable/fav_blue_icon" />
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_alignParentBottom="true"
android:background="#d7d7d7" />
</RelativeLayout>
</FrameLayout>
</FrameLayout>
</FrameLayout>
and in the java code you should add this
StikkyHeaderBuilder.ListViewBuilder.stickTo(mListView)
.setHeader(R.id.header, (ViewGroup) contentView)
.minHeightHeaderDim(R.dimen.min_height_textheader_materiallike)
.animator(new ParallaxStikkyAnimator())
.attatch_Acitivty(Attractions.this)
.castTo("Attractions")
.build();
and here is the library used
but i have modified this library to work as i want
the modification is add method in stcikylistview builder to know the activity used and pass a delegate for scrolling i used this because i added a blur for images in the viewpager
and her is my modification
i will upload the modified version of the library
here you are https://drive.google.com/file/d/0BxdN8PyW5nmHMmFFeFY2aW9zdlk/view?usp=sharing
I had this issue as well. You'll need to used RecyclerView. Now I understand you must use ListView and GridGiew, but you can use that within a RecyclerView.
For example, I'll show you how to implement a GridLayout within in a RecyclerView.
In your fragment layout (that you'd want to implement GridView in), add the following XML
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/recyclerviewGRID"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Then on your fragment java,
on your fragment onCreateView, define the RecyclerView,
RecyclerView rv = (RecyclerView) v.findViewById(R.id.recyclerviewGRID);
setupRecyclerView(rv);
Create the method setupRecyclerView,
private void setupRecyclerView(RecyclerView recyclerView) {
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new GridLayoutManager(recyclerView.getContext(), 2));
mAdapter = new AdapterGridView(getActivity().getApplicationContext(), mItems);
recyclerView.setAdapter(mAdapter);
}
You must define mAdapter as RecyclerView.Adapter first. Then create your the adapter for the RecyclerView. Note that, mItems is an ArrayList that will contain contents of your list.
AdapterGridView.java
public class AdapterGridView extends RecyclerView.Adapter<AdapterGridView.ViewHolder> {
ArrayList<AdItem> mItems;
Context context, contxt;
public AdapterGridView(Context context, ArrayList<AdItem> mItems) {
this.context = context;
this.mItems = mItems;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
//attach your list item layout here, mine in this case is called list_item_grid_item
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.list_item_grid_item, viewGroup, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
#Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
AdItem singleItem = mItems.get(i);
//attach data to your layout as the following manner
viewHolder.tvspecies.setText(singleItem.getName());
}
#Override
public int getItemCount() {
//return the number of list items
return mItems.size();
}
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public ImageView imgThumbnail, avatar;
public TextView tvspecies, adIDLBL;
public ViewHolder(View itemView) {
super(itemView);
itemView.setClickable(true);
itemView.setOnClickListener(this);
//define your list item views, basically the stuff in list_item_grid_item
imgThumbnail = (ImageView)itemView.findViewById(R.id.img_thumbnail);
tvspecies = (TextView)itemView.findViewById(R.id.tv_species);
}
#Override
public void onClick(View v) {
//handle item click events
}
}
}
When I open my navigation drawer in an android app I created, I'm still able to click on list items in my main layout (The content layout). I mean, I am actually able to click on a ListView item through my navigation drawer. I don't have any clickable items in the navigation drawer yet, but I've put it in a proper FrameLayout with a white background. The content of the drawer, I am designing in a fragment. Here is my code:
activity_home.xml (MainActivity)
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
tools:context=".HomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/toolbar_home"
layout="#layout/my_awesome_toolbar" />
<FrameLayout
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:id="#+id/fab_addContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="#dimen/view_margin_large"
android:layout_marginEnd="#dimen/view_margin_large"
android:layout_marginRight="#dimen/view_margin_large"
android:background="#drawable/fab_button"
android:contentDescription="#string/fab_contDesc"
android:padding="#dimen/view_margin_large"
android:src="#drawable/ic_add_white_24dp" />
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="#+id/drawer_frame"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"
android:clickable="true" />
</android.support.v4.widget.DrawerLayout>
fragment_drawer.xml (DrawerFragment to go into the #+id/drawer_frame )
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="144dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/material_design_wallpaper" />
<ImageView
android:id="#+id/iv_userThumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="16dp"
android:background="#drawable/display_pic_thumbnail"
android:contentDescription="#string/contact_thumbnail" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/view_margin_xx_large"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/shadow" />
<TextView
android:id="#+id/tv_userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tv_userEmail"
android:layout_alignLeft="#+id/tv_userEmail"
android:layout_alignStart="#+id/tv_userEmail"
android:layout_marginBottom="#dimen/view_margin_small"
android:text="Siddhant Chavlekar"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_userEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/view_margin_large"
android:layout_marginLeft="#dimen/view_margin_large"
android:layout_marginStart="#dimen/view_margin_large"
android:text="siddhant.chavlekar87#gmail.com"
android:textColor="#android:color/white" />
</RelativeLayout>
</LinearLayout>
Why is this happening? I'm using the AppCompat v7:r21 library to provide backwards compatibility for my Lollipop (Material Design) Apps.
So, I put the above mentioned line which is android:clickable="true" in my drawer_frame FrameLayout and so far I haven't come across any difficulties. Although, if I put it in my other layout, the bug still arises...
So I guess the solution is to put android:clickable="true" in the layout which represents the drawer. (The layout with android:layout_gravity="start")