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

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>

Related

Why can't I see the right side of my activity on my phone?

I'm trying to code an app for a school project. I'm stuck with the design. I can't see the right side of my activity on my phone, but it's appearing on the Android Studio preview. It's possible that my code isn't right or that i've didn't respect something.
And here are the 2 screenshots:
Android Studio Preview:
https://pasteboard.co/I6uT89f.png
Phone view:
https://pasteboard.co/I6uSgpW.jpg
Here's the code:
activity_main.xml
<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:background="#color/colorPrimaryDark"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
</android.support.design.widget.AppBarLayout>
<include
android:id="#+id/include"
layout="#layout/content_main" />
<com.leinardi.android.speeddial.SpeedDialOverlayLayout
android:id="#+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#131313"/>
<com.leinardi.android.speeddial.SpeedDialView
android:id="#+id/speedDial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:sdMainFabClosedSrc="#drawable/ic_menu"
app:sdOverlayLayout="#id/overlay"/>
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="340dp"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/header2"
android:scaleType="fitCenter"
android:layout_marginTop="-20dp"/>
</RelativeLayout>
<RelativeLayout
android:clickable="true"
android:focusable="true"
android:id="#+id/plante1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:background="#drawable/ripple"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="-10dp"
android:layout_marginBottom="15dp"
android:gravity="center">
<RelativeLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="10dp"
android:background="#drawable/logo_shape">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<fr.visufo.titouan.jardin.UnderlinedTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="0dp"
android:gravity="left"
android:text="Plante 1"
android:textSize="20dp"
android:fontFamily="#font/raleway_light"
android:textColor="#000000"
app:underlineColor="#6DB85C"
app:underlineWidth="10px"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="80dp"
android:layout_marginTop="30dp"
android:textSize="15dp"
android:textColor="#000000"
android:text="Pensez à rentrer votre plante demain"
android:fontFamily="#font/raleway_light"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="335dp"
android:layout_marginRight="7dp"
android:layout_marginTop="-4dp"
android:background="#drawable/degrees_shape">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="0°C"
android:gravity="center"
android:fontFamily="#font/roboto"
android:textSize="18dp"
android:textColor="#636363"/>
</RelativeLayout>
</RelativeLayout>
There are 8 similar relative layouts showing quite the same thing, here's
only one
</LinearLayout>
</ScrollView>
#titouan-pellerin - Unlike using div as a container for (most) things as in Website Design, you don't need to be repeatedly wrapping each individual view inside of it's own layout..For Example, if I wanted to my activity to vertically show something like this:(Title)(some smaller subtext)(An Image)(Some Description text)(And two buttons at the bottom)..I wouldn't wrap each of these things individually in their own layout - I would simply create 1 base layout (to act as the main container), and then inside of it, I would create 1 vertical layout for the content (arranged vertically), and 1 horizontal layout for the Buttons at the bottom (arranged horizontally).Of course you will also want to set your margins according to how you want everything displayed.You are most likely experiencing issues due to a mixture of margins getting added together over and over again and expanding past the screen's boundaries, combined with the fact that the phone is likely of different pixel density and resolution compared to the emulator.Step 1: Fix your Layout, as I described above.Step 2: Choose/Setup an Emulator that matches your Device most closely in Resolution/PixelDensity.Hope this helps!If you found this to be a good explanation, please accept this as the answer to your question.Thanks, and happy coding!

Recyclerview with fixed height wont scroll inside nested scroll view

I have a RecyclerView with a fixed height inside a NestedScrollView with a few other layouts inside it. The recycler view won't scroll, but it scrolls fine if I set its height to wrap_content.
I cannot make the RecyclerView use wrap_content because there is an issue with EndlessRecyclerViewScrollListener that it keeps loading data from the server and pushing it into my Adapter even if the user has not scrolled down at all.
Most are suggesting to set nested scrolling to false, but if I disable nested scrolling, the NestedScrollView does not allow me to scroll my RecyclerView. But if I leave nested scrolling enabled, the scroll view does not scroll unless I start touching from outside the RecyclerView.
My layout code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:background="#color/scoop_background"
tools:context=".module.scoop.timeline.ScoopTimelineFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="92dp">
<ImageView
android:id="#+id/ivTimelineBanner"
android:layout_width="match_parent"
android:layout_height="92dp"
android:layout_margin="0dp"
android:clickable="true"
android:padding="0dp"
android:scaleType="fitXY"
android:src="#drawable/banner_placeholder" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingLeft="92dp">
<TextView
android:id="#+id/tvGroupMembership"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="#dimen/text_content" />
<TextView
android:id="#+id/tvGroupName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="#dimen/text_header"
android:textStyle="bold" />
<TextView
android:id="#+id/tvGroupMemberCount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="#dimen/text_content" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#null"
android:paddingStart="#dimen/divider_normal"
android:paddingEnd="#dimen/divider_normal"
android:src="#drawable/ic_chevron_right_white_24dp" />
</LinearLayout>
</FrameLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeRefreshLayoutTimeline"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="4dp">
<android.support.v7.widget.CardView
android:id="#+id/cvCreateScoop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/divider_small"
android:layout_marginRight="#dimen/divider_small"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="#dimen/divider_normal">
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:src="#drawable/svg_nav_create_scoop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingStart="#dimen/divider_normal"
android:text="What's on your mind?"
android:textSize="#dimen/text_content" />
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:padding="#dimen/divider_xsmall"
android:src="#drawable/svg_insert_image" />
</LinearLayout>
</android.support.v7.widget.CardView>
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:overScrollMode="never"
android:nestedScrollingEnabled="false"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingBottom="4dp">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
What do I have to modify so that the RecyclerView is scrollable, but the whole NestedScrollView also scrolls along with it, so that if the user is scrolling back up (swiping from top to bottom), the RecyclerView will scroll along with the NestedScrollView, which will bring the layouts above RecyclerView.
To visualize:
The layout I'm trying to achieve is similar to that of facebook's. When you scroll down, the timeline will scroll down, and the search bar with the messenger icon at the top is also scrolled so that it is hidden when scrolling down. When you scroll up, the timeline is being scrolled back up, and showing the search bar again.
I decided to do it differently because I wasn't able to solve it with this method. Instead, I used a CollapsingToolbar and put the other layouts inside it, then removing its background so it does not look like a toolbar, and it seamlessly does what I wanted to, just with a different implementation.

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.

Recyclerview inside viewpager only extends the length of the viewpager

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.

Android Toolbar layout is horizontal

I'm trying to use a couple views within a support.v7.widget.Toolbar, but it looks like they're all placed as if in a horizontal LinearLayout. I'm looking to create something more like this where the EditText ends past the overflow menu, rather than where the overflow menu begins. Here's my currently layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="250sp"
android:background="#color/primary"
android:gravity="bottom"
android:minHeight="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button_id"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/url"
android:textColor="#color/accent"
android:textSize="16sp" />
<EditText
android:id="#+id/url_text_field_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:maxLines="1" />
<TextView
android:id="#+id/output_text_view_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/initial_output_text_id"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Here's a screenshot. You can see the views are in line with the share button and overflow menu. The title is also hidden on the left hand side by the views. How would I have a second row for my views in the Toolbar so they span the width of the page? Hopefully, I'm just missing something small, as I'm new to Android. Thanks in advance for the help.
You could, probably, put a vertical LinearLayout into your Toolbar

Categories

Resources