How to resize image as I scroll? - java

I have a ScrollView in which I have inserted a ConstraintLayout that contains a fullscreen ImageView and some other components below it.
What I want is for the image to shrink in height (to a certain limit) whenever I scroll down.
Here's an example of what I'm seeking: https://imgur.com/rlOr0HA
As for resizing, after some research I figured I'd have to create a LayoutParams object and then affect it to the ImageView. No problem there.
But as for detecting the scroll event, I've had some trouble. I tried the setOnScrollChangeListener on my ScrollView, but the problem is that it requires an API level of at least 23. So I wonder if there is another solution that works for lower levels as well.
Another problem I'm having is how to make the resizing proportionate to how much the user has scrolled.

You are looking to do the coordinator layout with a collapsing toolbar. This is built into android and you do not need any code changes. The inflater will inflate the layout and everything will work.
In your xml layout file you will need
<coordinatorlayout
<Appbar layout
<collapsingtoolbar
<ImageView> <-- your image goes here
/collapsingtoolbar
/Appbar layout
/coordinatorlayout
<nestedscrollview
<textview> <--Your content that moves up goes here
/nestedscrollview
<floating action button> <-- your example shows one of these buttons but its optional

Related

How to make dimming effect of Youtube when motionLayout transitions from start to end?

I'm trying to make this effect but has no idea, how to achieve it:
My idea is to have a Frame Layout which wraps the video fragment, and the Video fragment has motion Layout as its root layout. So, Frame Layout is in main Activity, but motion Layout is inside a .xml file, which will soon be inflated as the Video fragment's layout. It looks something like this (The frag container will match parent in its width and height):
My questions are:
Is this a good idea to make this transition?
How to make the dimming effects that YouTube has? I'm planning to use this Listener for tracking the transition but has no idea how to make the slowly dimming effect :(. MotionLayout.TransitionListener
Any idea?
One way I can think of cover the screen with a a View that is
#000000 and transition the views color to #FF000000 using a custom Attribute.
The View would need to be gone, Invisible, or translationZ = -1 at the start

Layout scrolling ripple effect

How could this scrolling behavior be accomplished?
Screenshot
To be specific, I need the wave effect to be shown whenever I try to scroll and reach the limit of a layout. Is there some property that I can tweak?
To get this wave effect, use any horizontally or vertically scrollable view as a container layout in your layout XML.
For example: ScrollView, HorizontalScrollView, NestedScrollView
List and Grid layouts like ListView, RecyclerView also has this scrolling effect.

Eclipse android widget moving

I am designing my activity screen using eclipse but whenever I move an object e.g. a button it snaps around and I find it hard to position things where i want them.
Is there some setting I can change as as soon as I add a second button it snaps the other button to another position it is so annoying!
Also if I have an image button why can't i resize this, even with a normal button if i try to make it larger it just fits to the text and wont make the button bigger or it just flicks to a random place on the activity?
thanks
Probably you're trying to place components freely in the View but you're not considering the LayoutManager behavior. If you try to position your component in a LinearLayout, for example, the components will be placed following its rules, and these components will not stay where you drop them.
Try to understand better how the layouts works on Android. But for now, the AbsoluteLayout or RelativeLayout may be what you're looking for.
About the components size, you'll need to understand better how to use layout properties for these components. See the question How to size buttons for more information.

Alternative to dp for text view alignment with background

I have a text view on my android app which I want to place in a specific place on the screen. This is because there is a background on the screen and the text view has to show in line with the space I have made for it in the background.
I'm moving the text around using the margins and entering for example 20dp for top margin 10dp for right margin.
Is there any other method I can use in order to ensure that the text view will be displayed in the right place on all devices? As other dvices mas have a higher or lower res.
use relativelayout and you can control the position of a view in a much better way.
android:layoutalign_parentright=true tag makes the view to be the right always.
android:align_right="#id/someViewId" makes the right edge of this view aligned with the right edge of someViewId view.
It packs a lot of tags that enables you to do such stuff.

scroll view issue Android

I am adding layouts programmatically.I have added a scrollview as a parent layout and a combination of horizontal and vertical linearlayouts when I add a list view in the scrollview I am getting an issue that my UI is not taking full screen although the listview height is set to fill parent .There is a blank space added at the bottom and the height of the listview gets very small .I haven't find the reason why it's happening, is it a bug in android for scrollview ?
fill_parent won't work. Try setting android:fillViewport="true".
Without any code, I'd have to take a guess and say that your ScrollView is not set to fill_parent.
Try using layout editor in Eclipse or the hierachyviewer that ships with the Android SDK to examine your layout in the emulator and see which view is not filling the screen.

Categories