Nabeel Ali
Nabeel Ali

Reputation: 74

Scrolling problem - doesn't scroll back when i move up the scroll bar

I am implementing Recycler View and Card View in Xamarin android for Notification ui xml. I got confused that when i run my code it works clearly but when i scroll up it gives a big distance between one notification to another. Here is a code of main activity and a screen shot of output.

using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using Android.Support.V7.Widget;
using App22.Helper;
using System;
using System.Collections.Generic;
namespace App22
{
    [Activity(Label = "@string/app_name", Theme = "@style/Theme.AppCompat.Light.NoActionBar", MainLauncher = true)]
    public class MainActivity : AppCompatActivity
    {
        private RecyclerView recycler;
        private RecyclerViewAdapter adapter;
        private RecyclerView.LayoutManager layoutManager;
        private List<Data> lstData = new List<Data>();

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            InitData();

            recycler = FindViewById<RecyclerView>(Resource.Id.recyclerView_Notifications);
            recycler.HasFixedSize = true;
              //layoutManager = new LinearLayoutManager(this);
            layoutManager = new GridLayoutManager(this, 1, GridLayoutManager.Vertical, false);
            recycler.SetLayoutManager(layoutManager);
            adapter = new RecyclerViewAdapter(lstData);
            recycler.SetAdapter(adapter);
        }
        private void InitData()
        {
            lstData.Add(new Data()
            {
                userProfile = "you can write here base 64 string of image",
                issueInfo="abc",
                tvtime_noti="24m",
                userName="Nabeel"
            }) ;
            lstData.Add(new Data()
            {
                userProfile = "you can write here base 64 string of image",
                issueInfo = "abc",
                tvtime_noti = "24m",
                userName = "Nabeel"
            });
            lstData.Add(new Data()
            {
                userProfile = "you can write here base 64 string of image",
                issueInfo = "abc",
                tvtime_noti = "24m",
                userName = "Nabeel"
            });
            lstData.Add(new Data()
            {
                userProfile = "you can write here base 64 string of image"
                issueInfo = "abc",
                tvtime_noti = "24m",
                userName = "Nabeel"
            });

Here is also a github link if you want to download and check it. and screen shot which gives you better information.

when i scroll up it gives much space between two notifications

Upvotes: 1

Views: 95

Answers (1)

Lucas Zhang
Lucas Zhang

Reputation: 18861

Set the line android:layout_height="match_parent" to wrap_content in notification_items.xml .

enter image description here

Upvotes: 2

Related Questions