I'm currently working on a Grade Manager for school written in Java for Android 6. I just started with Android so I'm no expert.
The Problem:
If I call the method notifyItemRemoved() on my RecycleView Adapter and the last CardView moves from the left bottom place to the upper right place, the View is resized and the animation is cut of.
Now I don't know why that view is resized because RecycleView's layout_height attribute is match_parent.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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=".SemesterActivity"
tools:showIn="#layout/activity_semester">
<android.support.v7.widget.RecyclerView
android:id="#+id/subject_list_view"
android:padding="20dp"
android:layout_below="#+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
</android.support.v4.widget.NestedScrollView>
I took a GridLayoutManager as LayoutManager for the RecycleView.
subjectListView.setLayoutManager(new GridLayoutManager(ActivityContext, 2));
How i update the RecycleView:
SubjectAdapterObj.notifyItemRemoved(viewHolder.getAdapterPosition());
The animation is the default animation.
Could the GridLayoutManager be the problem?
Video Example:
Sorry. English is not my native language.
So I finally found out what the problem was.
It actually was the NestedScrollView which resizes it's children.
So what you need to do is to simply add android:fillViewport="true" to your NestedScrollView.
Thats it. I hope it helps someone although it's not a really difficult bug. I just searched at the wrong places.
Related
Okey, so hello everyone.
I am pretty new to app developing.
Introduction:
In my app I have activity with RelativeLayout. In this layout I have zoomable FrameLayout. In this layout I have to have only one layout. In my case It is another RelativeLayout. Finally in this layout I have number of ImageViews. Purpose of this activity is show layers of map (drawables) via switches.
Code here:
<?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"
android:background="#color/colorDarkBlueGrey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.example.cotwcompanion.ZoomableView
android:id="#+id/zoomView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/mapLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/mapBCG"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:contentDescription="#string/map_name"/>
<!-- Here I generate other ImageViews with 'same' attributes -->
</RelativeLayout>
</com.example.cotwcompanion.ZoomableView>
<!-- Here are other layouts -->
</RelativeLayout>
Problem:
My problem is more or less visual. I would like to show these layers (1:1 ratio) as big as display allows (vertically). Therefor I need to overlap display's width.
What I need It to look like:
IMAGE
What I have tried:
I thought FrameLayout would do it. So I tried to set its width
and height programmatically, so It fits screen height and has
the same width, because of 1:1 ratio mentioned before. If I try to log these dimensions, it seems like all is set. Because
of match_parent attribute in ImageViews and their parent RelativeLayout, It should therefor do everything else and stretch these Views to fill FrameLayout. But everything just
only fits screen width.
Image of result here:
IMAGE
Code here:
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(height, height);
FrameLayout frame = findViewById(R.id.zoomView);
frame.setLayoutParams(lp);
I tried the same method with normal FrameLayout but got same
result.
I also tried to exchange FrameLayout with
HorizontalScrollView and custom zoomable ImageView. This worked more or less well, but problem was when I zoomed the map.
Horizontal scroll disrupt every movement with zoomed map. Therefor I
tried to create custom HorizontalScrollView with methods to
disable scroll. Even when I catched zoomed state from ImageView
and set scroll to notEnabled, It still did not work.
And there you go. Like I said zooming methods and everything other works. I just need to somehow have bigger View than display allows.
EDIT [21.11.2020]:
So as Daxi suggested I tried to change RelativeLayout in ZoomableLayout to ConstraintLayout. I also changed ZoomableLayout to extend from ConstraintLayout. That almost solved my problem. However I could not scroll to left and right. I could only zoom. So I took one of my last tried solution and wrapped ZoomableView with HorizontalScrollView. Everything seemed okey. However I now just cannot scroll to the very 'start' or 'end' of the ImageView. It seems like I can only scroll within the base width of HorizontalScrollView and not width of ImageView. So I now need to solve this problem.
Code here:
<RelativeLayout>
<HorizontalScrollView>
<ZoomableView extends ConstraintLayout>
<ConstraintLayout>
<ImageView/>
.
.
</ConstraintLayout>
</ZoomableView>
</HorizontalScrollView>
.
.
</RelativeLayout>
I am so sorry if this is somehow a duplicate of other problem already described on stackoverflow, but I searched for solution over two days now and still did not find any. Maybe I am bad finder. If this will be the case, feel free to tell me. I will delete it if needed.
If there will be some pretty fine answer and solution I would really appreciate It. Thank you.
Would you consider using ConstraintLayouts? If yes, you could use it like this
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/mapLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/mapBCG"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="#string/map_name"/>
<!-- Here I generate other ImageViews with 'same' attributes -->
</androidx.constraintlayout.widget.ConstraintLayout>
However, I am not sure how exactly this will interact with your ZoomableView
I'm creating a simple app for personal use and I'm stuck because I need to add/remove a text from my scrollview. In the screenshot below the blue square is my scrollview and the mail button (placeholder) needs to open a popup where I can put 2 values in 2 different boxes, a string and a double.
Main_Activity
I know how to do almost everything but I don't know how to add a text every time I click on the mail button and it should look like this when I click on it
this is how it should be when is done
The left button of a car block is the "delete from scrollview" button that removes it from the scrollview and preferences and the right button that does like the 2nd image but where I can edit it.
My questions are:
How can I add a "block" of items in a scroll view? Per block I mean: Edit and delete button and the text like in the example.
Suggestions on what to use for the popup that adds 2 input fields?
In my opinion, I suggest to use recyclerView instead because of performance issues.
link
But, if you need to do the way using ScrollView just follow this.
In your 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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_blue_dark"
android:fillViewport="true"
android:padding="16dp">
<LinearLayout
android:background="#android:color/holo_red_light"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
And add item into linear layout when handle click event.
val linear = view.findViewById<LinearLayout>(R.id.linearLayout)
val item =
LayoutInflater.from(requireContext()).inflate(R.layout.item_list_row, linear, false)
linear.addView(item)
I have an activity page that I have placed images, buttons, etc. on. I am realizing it's going to be too large to fit on a mobile screen, so I want to make the page scrollable.
My current xml file for the activity looks like the following:
<?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"
tools:context=".bakers">
...
</androidx.constraintlayout.widget.ConstraintLayout>
I searched online and have tried multiple solutions, but the problem with every solution is that, though sometimes I'm able to scroll on the page, the format/layout of the activity gets all messed up.
For example, if I do this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
...
the format is still messed up. I've also tried to use a Relative Layout setup, but that doesn't help either.
Any suggestions?
add scrollView to the .xml file and put the objects that you want to be scrollable.
try this guide: https://www.youtube.com/watch?v=69C1ljfDvl0&t=287s
The code is in the description if you dont want to watch the video. hope it will help you.
I'm not sure if this is hard to do with a RecyclerView or not, I thought there was an easy way to do it but I'm having some difficulties.
I have a RecyclerView on a activity, and when I go to the activity, I want it to scroll to an item. Seems fine enough. However, my issue is that, say only 5 items fit on screen at a time, and we have 6 items, and we scroll to the 5th or 4th item, the recycler view does scroll a tiny bit, but it doesn't look like it scrolls 'to' the element, as it is confined by the RecyclerView bounds.
Is there a way to make it so if I scroll to the 4th or 5th item in the RecyclerView, it will position it at the top of the view, and the area below the last item will just be the background color of the normal view, and I can just scroll back up normally?
I hope I'm explaining myself correctly. I'm not sure if this can be done easily and I have made a mistake in the XML setup or code setup.
<merge 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:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/timelineSwitcherView"
layout="#layout/view_timeline_view_switcher"/>
<ViewAnimator
android:id="#+id/viewAnimator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/timelineSwitcherView">
<RelativeLayout
android:id="#+id/timeLineRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/lighterBlue">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/timeLineSwipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/timeLineRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
Appreciate any help and guidance with this.
You should use
mRecyclerview.scrollTo(x,y);
mRecyclerview.scrollToPosition();
Or even better:
mRecyclerview.smoothScrollBy( x , y);
mRecyclerview.smoothScrollToPosition(List item position);
So you need to get the Y position, or the child position in the list.
I have a main menu screen with a simple ListView that contains "links" to further screens in my app (Browse, Bookmarks, Settings, About, etc.). Underneath the ListView there is a TextView (more accurately, a TextSwitcher that rotates TextViews) that changes every 10 seconds to display a new "tip".
In portrait mode, this works fine. There are my five list items in the ListView , and my tip label underneath. However, when I switch to landscape mode, the ListView is taller than the screen. The ListView scrolls normally, but I cannot scroll past the end of the ListView to see the TextView underneath.
I have tried every possible combination of Layouts, wrappers, ScrollViews, and layout_height parameters and I simply cannot get it to behave.
Here is the simplest code I can use to get the result pictured above:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:orientation="vertical"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/ListLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ListView android:id="#id/android:list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
</ListView>
</LinearLayout>
<LinearLayout android:id="#+id/TipLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#+id/ListLayout">
<TextSwitcher android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TipSwitcher">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="7pt"
android:id="#+id/Tip1TextView" android:text="Tip: Hello, Android!"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tip: This is the second TextView in the TipSwitcher!"
android:id="#+id/Tip2TextView" android:textSize="7pt"></TextView>
</TextSwitcher>
</LinearLayout>
</RelativeLayout>
Like I've said, I've already tried so many different combinations that I can't list them, and for the most part I was randomly inserting XML in an attempt to get something to work the way I wanted. So I'd greatly appreciate suggestions as to how I would go about doing this the right way.
Thanks.
EDIT: Something I forgot to mention, this may or may not be relevant. My MainMenuActivity is extending ListActivity. According to the docs, "ListActivity has a default layout that consists of a single, full-screen list in the center of the screen." But, "If you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate()." So I don't think the ListActivity is interfering.
Put the TextSwitcher in the ListView itself. You can use addFooterView() for this.