Recyclerview inside viewpager only extends the length of the viewpager - android

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.

Related

Two recycleviews in one activity scroll problem

I have created 2 recycleviews in one activity. One scrolls horizontally while other scrolls vertically. I can scroll correctly inside each RecyclerView but the page as a whole won't scroll i.e. top RecyclerView stays at the top always and bottom one stays at the bottom like both are fixed in position.
<ScrollView
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:orientation="vertical"
tools:context="com.shakeelnawaz.recipes.AllRecipesFragmet">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="#string/trending_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/horizontaltrendingrecycleview"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginStart="15dp"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="#string/all_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
I read this post "Scolling with multiple RecyclerViews in Layout" and set vertical recycleview's height programmatically. like this
LinearLayout.LayoutParams params = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
// calculate height of RecyclerView based on child count
params.height=1150;
// set height of RecyclerView
recyclerView.setLayoutParams(params);
But the problem is that how I can calculate the height of RecyclerView based on child count?
Use NestedScrollView instead of ScrollView
and use this below line in your Fragment in Activity.
ViewCompat.setNestedScrollingEnabled(mYourRecycleView, false);
This will be work on all your Android API level.
Replace ScrollView with NestedScrollView
Then add: horizontaltrendingrecycleview.isNestedScrollingEnabled = false
Your XML should look like below:
<android.support.v4.widget.NestedScrollView
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:fillViewport="true"
tools:context="com.shakeelnawaz.recipes.AllRecipesFragmet">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="#string/trending_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/horizontaltrendingrecycleview"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginStart="15dp"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="#string/all_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

Communicate between fragments and layouts

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.

Recyclerview within a Scrollview dont coordinate

I have this activity design, which shows a card view inside a scrollView, But under that cardview I need to put a listview or recyclerview. The problem is that I need the scroll of that list to coordinate with the main scroll. Osea that when lower in the content the cardview will disappear and the list of the recyclerview or listview will be crossed.
I need all the content to respond to the main scroll to show up and disappear after titlebar, Which should I change or redesign?
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
app:cardElevation="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/post_coordinator"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/post_bg"
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="fitXY"
android:src="#drawable/default_profile" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
android:src="#drawable/ic_hot_black"
app:layout_anchorGravity="bottom"
android:layout_marginLeft="16dp"
app:layout_anchor="#id/post_bg"
android:tint="#FFF"
/>
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_anchor="#id/post_bg"
app:layout_anchorGravity="center_horizontal|bottom"
android:src="#drawable/profile"
app:civ_border_color="#FFF"
app:civ_border_width="3dp"
/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
android:src="#drawable/ic_hot_black"
app:layout_anchorGravity="bottom|end"
android:layout_marginRight="16dp"
app:layout_anchor="#id/post_bg"
android:tint="#FFF"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginTop="205dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingBottom="50dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepare your Anus Cersei Lanister, You Gonna Die"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Large"
android:textColor="#2d2d2d"
android:textAlignment="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="#string/emilia"
android:textColor="#color/secondary_text"
android:layout_marginTop="10dp"
/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v7.widget.CardView>
<ListView
android:id="#+id/post_comments"
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
</LinearLayout>
</ScrollView>
Add your recyclerview inside NestedScrollview.
Also add recyclerview.setNestedScrollingEnabled(false);
Use android:fillViewport="true" to your ScrollView. ListView that located inside ScrollView works properly.
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
I'd recommend putting the CardView inside the RecyclerView as a header, and then you don't need the top ScrollView, the card and the list items would all be scrollable within the RecyclerView.
There are many ways to add a header to a RecyclerView, see here:
Is there an addHeaderView equivalent for RecyclerView?

RecyclerView with table like layout and Sticky header -- Originally tried NestedScrollView with no success

I am building a daily schedule like for students. This schedule is in a fragment. I need a sticky header with seven day labels and then the items need to scroll underneath, all at once. In addition I need the entire view to scroll horizontally.
Currently I have a HorizontalScrollView, some nested LinearLayouts, and a NestedScrollView. There are 7 RecyclerViews that are children of the NestedScrollView, one for each day of the week. This is so that I can call setNestedScrollingEnabled(false) on each RecyclerView so they scroll together. Currently the result is that the NestedScrollView clips the RecyclerViews to 1 item and no scrolling is possible. If I remove the NestedScrollView The RecyclerViews all scroll individually which is not what I want.
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp" />
<FrameLayout
android:layout_below="#id/toolbar"
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
fragment_schedule.xml
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ProgressBar
android:id="#+id/loading"
android:layout_width="74dp"
android:layout_height="74dp"
android:visibility="gone"
android:layout_gravity="center"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
...7 ImageViews representing days of week...
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_marginTop="8dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/sunday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/monday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/tuesday_list"
android:layout_width="84dp"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/wednesday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/thursday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/friday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/saturday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
tools:background="#color/accent_gold"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</HorizontalScrollView>
The only thing of note in the fragment class is that I call setNestedScrolledEnabled(false) after populating and attaching all of the adapters.
Any insight is greatly appreciated!
The solution in this case is that I was thinking about the requirements too rigidly. I changed my layout to consists of a The header linear layout, a scrollview, and a horizontal recycler view, with each day being an item. In the adapter the item layout is simply a LinearLayout that I programmatically add the class views to(as there is a finite number of classes per day). Scrolling works in both directions. I will retitle the question so hopefully someone can find this working towards similar requirements.
Fragment xml
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ProgressBar
android:id="#+id/loading"
android:layout_width="74dp"
android:layout_height="74dp"
android:visibility="gone"
android:layout_gravity="center"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
...Image Views Representing Days of Week...
</LinearLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/day_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</ScrollView>
</LinearLayout>
</HorizontalScrollView>
RecyclerViewItem.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="84dp"
android:layout_height="match_parent"
android:id="#+id/item_schedule_layout"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="0dp">
</LinearLayout>
Then programmatically add views to the LinearLayout. My views for each class were complex so I created a custom view based on the layout I needed for each class and then was able to just define a new instance in a for loop and add it to the LinearLayout.

View not centered in fragment in ViewPager and RecyclerView Hidden by Toolbar

I have a ViewPager integrated with a TabLayout that displays 4 fragments (4 tabs). Each of those fragments are RecyclerViews that display lists of items. The number of items in each list is generated by a given date but sometimes there will be no items displayed. When this happens I switch to another fragment that displays in a TextView "No Games Scheduled".
The problem is that text is not centered in the screen. It is positioned kind of in the center but towards the bottom. I believe it has to do with my ViewPager attribute in XML where I set it to app:layout_behavior="#string/appbar_scrolling_view_behavior" (Note: this line is not displayed in posted code. I explain later.)
When I click on the xml code for the ViewPager, in the preview screen, (in Android Studio) the blue section that lights up is extended below the screen. So I know it has to do with that. When I remove that line of code the blue section fits the screen. As a test, I set the TextView displaying "No Games Scheduled" layout_gravity to center|bottom and when I ran the app, the text was not showing on screen. So I know it's being hidden by that line of code in the ViewPager. But I need it because I want the toolbar to hide when scrolling down and show when I scroll up.
I then tried removing app:layout_behavior="#string/appbar_scrolling_view_behavior" from the ViewPager and placed it in each of the fragments. It works but now the top of each fragment is being covered by the Toolbar and the Tabs like this (not my program, because I'm not allowed to show the UI, but it shows my exact problem):
How can I fix this? Thanks for any help!
main_activity.xml:
<android.support.v4.widget.DrawerLayout
android:id="#+id/nav_drawer"
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.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true">
<include layout="#layout/toolbar"/>
<android.support.design.widget.TabLayout
android:id="#+id/main_activity_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/light_black"/>
<LinearLayout
android:id="#+id/league_and_date_title_view"
android:layout_width="match_parent"
android:layout_height="34dp"
android:background="#color/gray"
android:orientation="horizontal"
android:paddingEnd="0dp"
android:paddingLeft="4dp"
android:paddingRight="0dp"
android:paddingStart="4dp"
android:weightSum="1">
<TextView
android:id="#+id/league_title_header"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|start"
android:paddingEnd="0dp"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:paddingStart="5dp"
android:textSize="14sp"
android:textColor="#color/green"
tools:text="League"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center|end"
android:orientation="horizontal">
<ImageButton
android:id="#+id/previous_date_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="#string/prev_date_button"
android:src="#drawable/previous_arrow"/>
<TextView
android:id="#+id/display_date_text_view"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:textColor="#color/outnix_orange"
android:textSize="14sp"
tools:text="Date Goes Here"/>
<ImageButton
android:id="#+id/next_date_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="#string/next_date_button"
android:src="#drawable/next_arrow"/>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/main_activity_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ProgressBar
android:id="#+id/loading_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
<fragment
android:id="#+id/fragment_nav_drawer"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_nav_drawer"
tools:layout="#layout/fragment_nav_drawer"/>
</android.support.v4.widget.DrawerLayout>
One of the fragment's layout:
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
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.v7.widget.RecyclerView
android:id="#+id/all_games_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_black"
android:paddingBottom="8dp"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
Fragment I switch to when no items are in the RecyclerView:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_black">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/no_games"
android:textColor="#color/white"
android:textSize="18sp"/>
</RelativeLayout>

Categories

Resources