Android - Recyclerview not starting from the top - android

I've already seen similar problem and tried all kind of solutions, this is what I ended up with:
layoutManagerMemes = LinearLayoutManager(
this#MainActivity,
LinearLayoutManager.VERTICAL,
false
)
recyclerViewMemes.setHasFixedSize(false)
recyclerViewMemes.adapter = adapterMemes
recyclerViewMemes.layoutManager = layoutManagerMemes
recyclerViewMemes.scrollToPosition(0)
The XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="#000000"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.NoActionBar">
</androidx.appcompat.widget.Toolbar>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewMemes"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</RelativeLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Could the issue be the images that are loaded after RecyclerView is set?
Ignore this: Stackoverflow demands some more text, Enter each item on a new line, choose the amount of groups unders settings, and click the button to generate your randomized list. Don't like the first team? Just click again until you do

Apparently the only way to avoid it is to know the image dimensions and set them before the image is loaded by calculating the ratio

Related

Is it possible to detect scroll in a view and scroll a bottomsheet accordingly?

My activity is something like
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#E7E7E7"
app:layout_constraintBottom_toTopOf="#+id/dummy"
app:layout_constraintTop_toTopOf="parent">
<include
android:id="#+id/bottomSheet"
layout="#layout/bottom_sheet_persistent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<View
android:id="#+id/dummy"
android:background="#F44336"
android:layout_width="match_parent"
android:layout_height="80dp"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
And the bottom sheet is as bottom_sheet_persistent.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="false"
app:behavior_peekHeight="80dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<View
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#2196F3"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
The screenshot is
As you can understand from the xml that, the red part is just a static view and blue is the bottomsheet. The bottomsheet also works as expected. What I wanted to achieve is, when the user start scrolls from the static view (Red View), I would like to scroll up the bottomsheet.
Thanks in advance.

ListView in ConstraintLayout not displaying

Been knocking my head for hours trying to figure out what am doing wrong with this. I have a ListView in a ConstraintLayout that isn't being displayed. I am just getting accustomed to using ConstraintLayout so u'll forgive me for any silly mistakes. These are my layout files
activity_main.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="#layout/content_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ListView
android:id="#+id/noteList"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
The ListView in the above file doesn't display at all but when I substitute the ListView with a RecyclerView, the list is displayed.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/noteList"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
What am I doing wrong with the ListView that makes it not work and yet RecyclerView works fine?
If you want to preview your ListView in design mode, you'll have to use the tools namespace.
Add something like this to your XML file;
tools:listitem="#android:layout/simple_list_item_1"
Then add the tools namespace to the top of your XML file like so;
xmlns:tools="http://schemas.android.com/tools"
So, your file should look like this;
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
xmlns:tools="http://schemas.android.com/tools"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ListView
android:id="#+id/noteList"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:listitem="#android:layout/simple_list_item_1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
That way you'll be able to preview your list view.

RecyclerView last item is cut off onResume of fragment

Problem
RecyclerView functions properly and no view is cut when not opening a detailFragment. But it cuts off the last item of my RecylerView item whenever I return back from the detailFragment launched by the recylcerview item.
I only encounter this on my emulator which api 26. When I run it in my api 28 phone it works properly. But I think I might be missing something.
fragment_main
<?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="match_parent"
android:fitsSystemWindows="true"
android:background="#color/colorWhite">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/fragment_main_abl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:background="#color/colorWhite"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/fragment_main_ctbl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="#android:color/white"
app:expandedTitleTextAppearance="#color/colorPrimaryText"
android:fitsSystemWindows="true">
<include layout="#layout/header_fragment_main"
app:layout_collapseMode="parallax"/>
<androidx.appcompat.widget.Toolbar
android:id="#+id/fragment_main_tb"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<com.google.android.material.tabs.TabLayout
android:id="#+id/fragment_main_tl"
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_main_tl_height"
app:tabMode="scrollable"
app:tabSelectedTextColor="#color/colorPrimary"
app:tabTextColor="#color/colorUnselected"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/fragment_main_vp"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
fragment_child
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:background="#android:color/white"
>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/fragment_child_rv"
android:layout_width="0dp"
android:layout_height="0dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
NOTE
I wish not to put bottom padding for my recyclerView. I have tried
this and it works but during the times that my recyclerView functions
properly an excess padding is seen at the bottom
I wish not to make use of nestedScrollView for my recyclerView if possible since I would like the recyclerView to recycle as much as possible
Replacing
app:layout_scrollFlags="scroll|exitUntilCollapsed"
with
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
solved my issue.

Image as Toolbar background that hangs outside of its bounds

I've tried using various layouts but that little bit that hangs outside the boundary of the rectangular toolbar doesn't work (the semi circle).
I want something like this:
How would I go about implementing this? I've something that visually looks like this but it is just an ImageView inside a relative layout. I want a proper Toolbar.
Well I do now know if you want this, but I've done this example for you, hope it helps.
This is the activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.constraint.ConstraintLayout
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="#color/colorPrimary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
</android.support.v7.widget.Toolbar>
<android.support.constraint.Guideline
android:id="#+id/guidelineImageStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent=".33" />
<android.support.constraint.Guideline
android:id="#+id/guidelineImageEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent=".66" />
<ImageView
android:id="#+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/overlape_image"
app:layout_constraintDimensionRatio="W,1:1"
app:layout_constraintLeft_toLeftOf="#id/guidelineImageStart"
app:layout_constraintRight_toRightOf="#id/guidelineImageEnd"
app:layout_constraintTop_toTopOf="parent" />
<include layout="#layout/content_main" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
Now you can play and adjust size of views.

Mapbox is not fully showing in viewpager in android

I'm using mapbox in my application, normal fragment page full mapview showing,but when using viewpager in that fragment, mapview is not showing full in bottom its showing black color in version 8.0.0, below versions is showing properly.
Here is an image, showing how it looks.
tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/rlay"
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:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="#+id/appBarLayout">
<android.support.design.widget.TabLayout
android:id="#+id/gs_tabLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/lightgray"
app:tabTextColor="#color/onegray"
app:tabSelectedTextColor="#color/onegray"
android:minHeight="?attr/actionBarSize"
app:tabTextAppearance="#style/MyTabStyle"
android:scrollbars="vertical"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:layout_below="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/gs_viewPager">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</RelativeLayout>
fragmenta.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:mapbox="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mapbox.mapboxsdk.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
mapbox:mapbox_cameraTargetLat="12.973520"
mapbox:mapbox_cameraTargetLng="77.633006"
mapbox:mapbox_cameraZoom="5"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v9"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1">
</com.mapbox.mapboxsdk.maps.MapView>
</android.support.constraint.ConstraintLayout>
Note: I don't know whether viewpager is problem or not, without tabs means its showing full map view. Please someone help me.
I know this can be a little late but when I faced the same problem, I did a little bit of reading and research to find out that the map when displayed through bootstrap Modal, angular, etc. shows default 400px width and will not take the previous container's width as it is not aware of it and hence its a good practice to use map.resize() method inside the map.on('load',function(){}) in the end of it.
While using bootstrap modal
map.on('load', function() {
// some code before the resize option
$('#myModal').on('shown.bs.modal', function() {
map.resize();
});
}
where my #myModal is the id of the Div that contains my bootstrap modal.
Hope this helps someone who is struggling with the same issue.

Categories

Resources