Android Recycle View Scrolling - android

hi I am building chat app using firebase realtime , facing issue with scrolling to last message -Bottom- when new message received , its working fine scrolling and every thing but not showing full height for the last item
here is my code
binding.items.smoothScrollToPosition(adapter.itemCount);
if any code to scroll with offset and how to calculate offset for dynamic height for message

I found soultion to use
layoutManager.stackFromEnd = true
final code is
val layoutManager = binding.items.layoutManager as LinearLayoutManager
layoutManager.stackFromEnd = true
binding.items.smoothScrollToPosition(adapter.itemCount)

Related

How to show the all items in recyclerview when you lock and unlock your phone?

Adapter is working fine when first time landed on that fragment.But the items of adapter not showing when I lock my phone and unlock it. When I printed the size and arraylist all data got printed but there is no items showing on the screen.
I tried to call notifyDatasetChanged but nothing happend. I want to know the reason that why data is not showing when I lock and unlock the phone after data showing successfully on the screen.
Code of binding in adapter -->
if (mDocUploadedImagesPathArrayList.size > 0){
binding.uploadedDocumentLayout.visibility = View.VISIBLE
documentListAdapter = DoctorDocumentImageAdapter(
requireActivity(),
mDocUploadedImagesPathArrayList,
this
)
} else{
binding.uploadedDocumentLayout.visibility = View.GONE
}
val mlayoutManager = GridLayoutManager(requireActivity(), 3)
binding.uploadedDocumentRecyclerview.layoutManager = mlayoutManager
binding.uploadedDocumentRecyclerview.isNestedScrollingEnabled = false
binding.uploadedDocumentRecyclerview.adapter = documentListAdapter
where mDocUploadedImagesPathArrayList is the list I am getting from the API
While changing GridLayoutManager in LinearLayoutManager this problem got solved and also this is only happens on Realme C3 model not on other mobiles.
Any idea why this is happening on Realme C3 and with GridLayoutManager not with LinearLayoutManager.

Android studio how to keep the chat scrolled down to the last message?

I'm working on a chat app. I want to keep chat shows the last sent messages(scrolled all the way down).
every time I reopen the chat or the keyboard shows, the messages scroll up.as shown here
recyclerView = findViewById(R.id.recycle_view);
recyclerView.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);
profile_image = findViewById(R.id.profile_image);
Although this line is supposed to fix the problem but it doesn't:
linearLayoutManager.setStackFromEnd(true);
How can I fix it ?
Try this, after getting/reading any new message run below code
recyclerView.scrollToPosition(messages.size() - 1);
This will scrollTo End of the message size.
You can use .setStackFromEnd(true) or .setReverseLayout(true)
setReverseLayout reverses the order of the elements, setStackFromEnd sets the view to show the last element.

appcelerator Android tableview crashes on setData SDK6

I have a tableview in a View XML and it crashes when I set the data via setData on SK6. Works fine on SDK 5, but on SDK6 it crashes when I assign the same data twice which I do when I need to switch data sets. This is only on Android as iOS works as it should
$table.setData(myDataSet);
$table.data = [];
$table.setData(newDataSet); // This is ok
$table.data = [];
$table.setData(myDataSet); // Re-assigning myDataSet crashes the table view
I am guessing this is a bug in SDK6 forAndroid - anyone else had the same issue?
Thanks
Nigel

Scrolling in android using Appium + Ruby

I am trying to scroll through the android app to find a specific element. Below is the code for scrolling:
def self.swipe_to (programme)
begin
scroll_to(programme)
rescue
puts 'unable to find ' + programme
return false
end
return true
end
The scrolling works fine however, the issue is the app scrolls to the programme but as soon the programme is found, the app scrolls back to the top of the list.
And then an error is thrown saying element could not be found.
Has anybody seen similar kind of issue before? Is there any way to stop scrolling as soon as programme is found? I just want to stop the scrolling back to the top as soon as programme is found. Please help.
I created a method to scroll to an element that is not on screen yet, because scroll_to was not working for me. This methos scrolls to any element on screen even if its not visible yet
def scroll_to_element(class_name, element_name)
ele_by_json(typeArray: [class_name], onlyVisible: false, name: {target: element_name, substring: false, insensitive: false})
end
Below code worked for me :
def scrollTo el_start, el_end
#get element coordinates start
el_start = $driver.find_element(:id, el_start)
screen_x_start = el_start.location.x
screen_y_start = el_start.location.y
#get element coordinates end
el_end = $driver.find_element(:id, el_end)
screen_x_end = el_end.location.x
screen_y_end = el_end.location.y
Appium::TouchAction.new.swipe(start_x: screen_x_start, start_y: screen_y_start, delta_x: screen_x_end, delta_y: screen_y_end).perform
end

Why do Images in Android aren't being shown on a TableView?

I'm working on Titanium 2.1.3 and deploying for both iOS and Android.
I'm having trouble displaying images on ImageView on Android in a TableView, if I do something like clicking on the search bar and show the keyboard then the images are shown or if I scroll the TableView the images appear and disappear with no apparent reason. It seems that unless I do something that forces a layout refresh on the TableView, the images aren't rendered.
The images are being loaded the same way in both Android and iOS, which is like this:
var itemIconHolder = Titanium.UI.createView({
width : '100dp',
left : '55dp',
height : "100%"
});
var itemIcon = Titanium.UI.createImageView({
left : '0dp',
height : '100%',
});
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "thumb-" + filename);
itemIcon.image = f;
itemIconHolder.add(itemIcon);
This problem doesn't happen in iOS, on iOS devices/simulator the behaviour is normal and flawless, but on Android devices/emulator it happens.
Do I have to load the images differently in Android? Am I missing something? I hope someone could help me in this one.
Thanks in advance.
EDIT
I tried these approaches:
itemIcon.image = f.read();
and
itemIcon.image = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "thumb-" + filename);
but the images still aren't rendered until I make something that causes the TableView to refresh in some way.
I found a workaround for this particular issue on Android.
Since it takes a layout refresh for the images to be rendered properly, what I did was to animate the table, moving it 1dp in a direction and at the completition of said animation I animated it again to return it to its original position. This is the code I used:
var table_bottom = '-1dp'
var tableAnimation = Ti.UI.createAnimation({
bottom : table_bottom,
duration : 100
});
tableAnimation.addEventListener('complete', function(e){
var table_bottom = '50dp';
if (osname === 'android')
{
table_bottom = '0dp'
}
table.animate({
bottom : table_bottom,
duration : 100
});
});
I've encountered this kind of problem with both Titanium SDK 2.1.3 and Titanium 3.0.

Categories

Resources