RecyclerView is not occupying full height - android

I'm working on a simple layout, but I found that RecyclerView is unable to occupy full height, but it wraps the height of its contents instead.
<?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">
<android.support.v7.widget.RecyclerView
android:id="#+id/gridList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#mipmap/bg_list" />
</LinearLayout>
The structure is super simple. What did I miss to let the RecyclerView fills up the whole screen?

Added layout should fill the screen height. If I use your layout wihout background, I am able to see correct output.
<?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">
<android.support.v7.widget.RecyclerView
android:id="#+id/gridList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
The problem seems at line android:background="#mipmap/bg_list". Check into bg_list which may affecting height.

Related

Margin to the scrollbar only (not to recyclerview) on recyclerview

My recycler view lies under my toolbar, as you can see from the first picture. However, I have a scrollbar on the right side of it. I have to give a margin-top to this scrollbar. I have tried with giving style. And I know about clip padding with padding-top and padding-bottom, however, I need this exactly. Are there any ways to make it real?
This is my problem
The result that I want
P.S. I know that it is not the best practice. I would appreciate any help. It is one of my first questions, don't judge me so strong. :)
My main XML file
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="?attr/background1"
android:keepScreenOn="true"
tools:context=".ui.main.HomeActivity">
<androidx.viewpager.widget.ViewPager
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pager" />
<include layout="#layout/toolbar_sura_detail" />
<include layout="#layout/player" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
My Fragment XML inside ViewPager
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?attr/background1">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/kuranDetailList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:fitsSystemWindows="true"
android:scrollbarSize="2dp"
android:scrollbarThumbVertical="#drawable/thumbforrecycle"
android:scrollbars="vertical"
android:orientation="vertical" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Try using this structure in your main XML and add scrolling layout behaviour for ViewPager
<androidx.coordinatorlayout.widget.CoordinatorLayout...
<com.google.android.material.appbar.AppBarLayout...
<androidx.appcompat.widget.Toolbar...
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pager"
app:layout_behavior = "com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>

Removing the extra top space in CoordinatorLayout- Android

I am trying to use BottomSheetBehavior to make a layout similar to what google maps is providing. I am successful in using the BottomSheetBehavior and create slide up layout. The problem I am having now is CordinatorLayout takes extra space even when my layout is collapsed.
Below is a screenshot of my layout.
White background in my main activity layout
Pink is my collapsed layout with peekHeight
And the grey background is the one which should be transparent but takes the extra space.
My main layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<include layout="#layout/sample_coordinator" />
</FrameLayout>
CordinatorLayout with BottomSheetBehavior
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/common_google_signin_btn_text_light_disabled">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="false"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<TextView
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#color/colorPrimary" />
</FrameLayout>
You have to use CoordinatorLayout in your activity layout.
Then in your bottom sheet layout insert these lines:
app:behavior_hideable="true"
app:behavior_peekHeight="Xdp"

In a fragment,when an image is set as the background of a RelativeLayout in ScrollView, the RelativeLayout is misbehaving

I have an activity with this layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity" />
Then I have this fragment layout, which I am transacting in the fragment_container of the activity:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_login">
</RelativeLayout>
</ScrollView>
The drawable bg_login is:
But the strange thing that is happening is, the background image(bg_login) hides all the content in RelativeLayout, in the preview pane as well as when I run the app. I can't find out why this is happening! Please help.
I dont know what you want to do, are you want have multiple background in relative layouts when scrolled or not.
But i assuming you, the scroll view when have a children element with background is not best practice.
So scoll view must set to a children from parent have a background for good practice.
This may be can help you :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_login">
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</ScrollView>
</RelativeLayout>

How to Scroll A Part of An Activity

I have a question that i couldn't Find Any Answer For it.
How can I Make An Layout Scrolling And Make Another Layout that doesn't Scroll?
On the other hand i want to make a layout Including Some buttons that scrolls if necessary and i want to put Two buttons at the bottom of the screen and i don't want them to disappear when scrolling.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.myname.myapp.MainActivity">
// a bunch of Buttons and TextViews
</RelativeLayout>
</scrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
// two Moveless Buttons
</RelativeLayout>
But it doesn't Work.
Your ScrollView has width and height that matches the parent. This means it takes up the entire space available leaving nothing for the RelativeLayout. You probably want to wrap what you already have inside a LinearLayout and then use layout_weight attribute to divide the space up.
I'm not sure I understand what You want to do. But try this and give feedback
( code example not tested in Android Studio)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.myname.myapp.MainActivity">
// a bunch of Buttons an TextViews
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp (for example)>"
android:layout_alignParentBottom="true">
// two Moveless Buttons
</RelativeLayout>
</RelativeLayout>
Make your root a vertical linearlayout with a scrollview, to hold the scrollable views, and a RelativeLayout, to hold your buttons.
You can take advantage of the LinearLayout's weighting ability by applying a weight of 1 to the Scrollview so it takes up as much room it can while the button-holding-RelativeLayout will be the size of your biggest button.
Here is an example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:background="#drawable/background"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.myname.myapp.MainActivity">
// a bunch of Buttons an TextViews
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
// two Moveless Buttons
</RelativeLayout>
</LinearLayout>
HTHS!

Making CardView width match parent even when elevation > 0

I wanted a cardview similar to this:
I wanted my CardView separated like that. The problem is, I don't know how to make CardView go edge to edge or match the width of the CardView to its parent. If I put shadows or setting the elevation at 4dp/8dp, the entire CardView adjusts to show the shadows on both end. Which is not what I want. This is worse when viewed on pre-lollipop.
I am believing this is just thick line separating it which can be done creating custom view with a custom drawable. But can this be done with just CardViews? I need my CardViews to go to the most edge and show separation at the bottom.
Here is my current layout. I created a separate layout file for each CardViews and included them in my fragment like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false"
android:fitsSystemWindows="true"
tools:context="com.neonwarge.android.notifire.activity.TaskActivity"
android:orientation="vertical">
<include
layout="#layout/cardview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<include
layout="#layout/cardview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
....
</LinearLayout>
And here is what generally a CardView looks like:
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
app:cardElevation="4dp"
app:cardUseCompatPadding="true"
app:cardPreventCornerOverlap="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingStart="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingEnd="#dimen/activity_horizontal_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:layout_marginTop="#dimen/activity_vertical_margin">
...
</RelativeLayout>
</android.support.v7.widget.CardView>
</merge>

Categories

Resources