Infinite image Scroll - java

I want realize a particular app in which you can scroll an image (background) infinitely. How can i do?
For example, my .xml is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/wallpaper" >
Thank you.

For infinite scroll you can use CWAC MergeAdapter. Here you can read what it is and how it works: https://github.com/commonsguy/cwac-merge

Related

How to add item blocks to a scrollview?

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)

Android Studio - make an activity scrollable without changing the current layout?

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.

Android Recycler View notifyItemRemoved animation cut off

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.

Android: ScrollView not scrolling with keyboard out

I've got a layout with some views, from which one is an EditText. The layout easily fits on one page, BUT, when the soft keyboard is out, the layout doesn't scroll.
Here's a recap of my layout:
<?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/background" >
<ScrollView
android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox/>
<TextView/>
<LinearLayout>
<EditText>
<requestFocus />
</EditText>
</LinearLayout>
<TextView/>
<LinearLayout>
<Spinner/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<Button
android:layout_alignParentBottom="true" />
</RelativeLayout>
And in my manifest I have declared the attribute:
android:windowSoftInputMode="adjustResize|stateHidden"
Does anyone know why it doesn't work and how to make sure it does work?
I had the same problem and I checked my activity in the manifest, and the reason why it wasn't working is because I didn't use this property:
android:windowSoftInputMode="adjustResize"
Now it works great and no need to do additional anchors.
Okay, apparently the ScrollView's android:layout_height mustn't be set to wrap_content. I set it to match_parent and set the android:layout_above to the button on the bottom of the page.
Don't ask me why, but this fixed the issue.
In my case, nothing of the above worked.
I had item name="android:windowTranslucentStatus">true</item> in my theme. And it was fixed by setting android:fitsSystemWindows="true" in the parent layout where is my scrollview.
Add android:windowSoftInputMode="stateHidden|adjustResize" to your tag in AndroidManifest.xml file. This will cause the screen to be resized to the left over space after the soft keyboard is shown. So, you will be able to scroll easily.
In my case any of the solution above does not work until I REMOVE
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
in my activity, I use that code to get a full screen display. Maybe for certain cases, try to remove any setup of full screen to make any of the above solution works.
If your First Fragment Scroll perfectly and the second fragment did not scroll then you should use the second fragment replace and do below things
1.Add in ScrollView
android:fillViewport="true"
android:fitsSystemWindows="true"
2.Add in Manifest
android:windowSoftInputMode="adjustResize|stateVisible"
If you add fragment then my suggestion is you need to Replace the Fragment
In my case I had to Remove the following property from my style to make it work .
<item name="android:windowFullscreen">true</item>
My problem was with a HorizontalScrollView. In my case I had to set HorizontalScrollView to:
android:layout_width="match_parent"
android:layout_height="match_parent"
And remove:
android:layout_above="#+id/closeButton"
android:layout_below="#+id/logo"
In the AndroidManifest.xml the activity is set to:
android:windowSoftInputMode=""
I hope this helps anyone comming across this weird bug.
In my case, what solved this was setting a missing constraint in the Bottom. My ScrollView had top, right, and left constraints, but no bottom one. After restricting it from all sides, it started to overlap the above textview, which prompted me to try putting the height to 0dp, and that seemed to solve the problem.
Try to set ScrollView as your parent layout. It works like charm for me!
<activity
android:windowSoftInputMode="adjustResize"
>
try this In android manifest ..

How to display an options menu like this when buttons are pressed?

I'm stuck figuring how to do the following requirement.
I need to make a simple screen with two buttons, like this:
That part of the screen is already done.
The hardest thing for me is to make the behavior of the two buttons
when they are pressed. In that case, they must show an option menu
below like this:
Button 1 Pressed:
Button 2 Pressed:
I didn't start to program the menu yet,but in case it helps, this is
the layout for the screen (without the buttons).
<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:orientation="vertical"
android:background="#color/grayBackgound"
tools:context=".MenuActivity" >
<include android:layout_width="match_parent" layout="#layout/header" />
<include android:layout_width="match_parent" layout="#layout/loggedin_subheader"/>
</LinearLayout>
The layout for the header:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/header"
android:contentDescription="#string/header"
/>
<ImageButton
android:id="#+id/btnClose"
android:src="#drawable/btn_close"
android:contentDescription="#+string/salir"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="260dp"
/>
</FrameLayout>
The layout for the sub-header is almost the same.
I just need help to make the options menu for every button.
Thanks in advance!
The menu that you want to implement is what is commonly called a QuickAction Dialog. There are several tutorials available for that.
To get you started, here is a few links:
http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/
https://github.com/ruqqq/WorldHeritageSite (This is not a tutorial per se, but has the complete implementation for the QuickAction Dialog)
https://code.google.com/p/simple-quickactions/ (You will need to make a few modifications in this)
The first link is the most promising in your case. If you scroll down that page to the Gallery3D-like QuickActions section, you will see it kind of resembles what you want the end result in your app to be. Naturally, goes without saying, you will still need to make modifications to the source available on the site.
Hope this helps. ;-)

Categories