Drag item to the next page on android - java

I have a viewpager including 3 pages. I set one viewgroup in each page and each of them has 4 items. Now I want to hold and drag one item from this page to another one.I already dealt with draging Item to the corner of the page but when moving to the new page, the new Item is not dragged. Is there any way to handle this problem?
Thanks :)

I haven't implemented drag and drop before so this might not work but perhaps you could make an invisible overlay view like a framelayout on top of the viewpager. Then handle all drag and drop coordination on this view.

Related

Limit the click area on the view android

I need to limit the click area on the view. For example, I have a full-screen view, but I need only the top of the screen to be clickable, while clicking on the bottom should not give a result, how can I implement this? adding on top of the container doesn't help
You will need to create a click listener ONLY on the view you want to respond.
TopView.setOnClickListener()
BottonView (nothing).
If for some reason, your top View is not independent, just create another view that is transparent, and set a clickListener on that.

Android : hide/show footer/header as scrolling scrollview down/up

I am trying to implement a way to have my footer slide away down and my header to slide away up while user scrolls down the scrollview.
And vice-versa, as the user scrolls up the scollview, I want my footer to slide in from the bottom and the header slide in form the top.
Regarding the animation, I have found this good library https://github.com/daimajia/AndroidViewAnimations that comes with a lot of nice animations.
The closest example for what I am looking for, is the default Android Twitter application that makes it's footer disappear as the user scrolls his timeline down and makes it reappear as the user scrolls up.
By header, I am not talking about the Android Toolbar (op AppBar or whatever). It's a customed-made UI element that I want to animate while the user scrolls.
Same thing goes for the footer : it's a customed-made UI element.
While looking for solutions, I stumble upon this answer https://stackoverflow.com/a/28712465/3535408 but it does not work.
Indeed, placing a Log.d inside the ifand else if shows that a simple touch with my finger triggers both a MotionEvent.ACTION_DOWN and a MotionEvent.ACTION_UP event. The same applies as I am sliding my finger up/down making the scrollview scrolls up/down : both events are triggered at the end when I stop touching the scrollview.
Is there a way to improve this solution ? Because as of now, as both MotionEvents are triggered, both animations are also triggered so the result is quite horrible.
Thanks !
An easy way to achieve that would be the following:
place the listview, the header and the footer inside a RelativeLayout
align the header with parent's top
align the footer with parent's bottom
add an empty header and footer to the listview with the same heights
catch the scrolling events on your listview and change the footer and/or header's translationY accordingly
But to answer your question, I'd say you should try a GestureDetector. It's way easier to manage the events - Detecting Gestures

Android Horizontal Scrolling that Snaps to List Items

I'd like to implement a UI experience in Android where a user can view a single item (for example, an item in my case is a collection of texts), and swipe left or right on the item to go to the previous or next item.
From my research, ListView does not implement horizontal scrolling. Potential candidates seem to be HorizontalScrollView and GridView, but I haven't seen any examples that can do this simply - only seemingly complicated libraries that need to be included.
My question is, is there a way to use ListView, HorizontalScrollView, GridView, or a combination of them to implement a horizontal scroll that shows one item at a time and snaps to the item being displayed?
The highlighted area in the picture below shows where I'm trying to implement this logic.
It looks like the best option to achieve this experience is a ViewPager, which requires the android support library.
http://developer.android.com/reference/android/support/v4/view/ViewPager.html

Keyboard hides content in fragment, I need the frame layout to resize so bottom is just above the keyboard and now scrollable

I have a fragment in my app that has a scroll view for the signup and login pages. Right now there isn't enough content in the scroll view to actually make it scroll, however when the keyboard appears, it does cover up most of the content in the view. This causes a lot of issues especially on devices with smaller screens, it blocks a lot, and the view is NOT scrollable, so I have to close the keyboard to get to the rest of the inputs.
I need the bottom of the fragments frame layout to be pushed up to JUST above the top of the keyboard, so the keyboard won't actually hide any content, and still allow the scroll view to actually scroll to the rest of the content.
I have seen the usual fix to an issue similar to this, which would to change the AndroidManifest.xml to the following:
android:windowSoftInputMode="adjustResize"
but this will push up the entire page, which includes the footer view I have under and outside of the login and signup fragment layouts. It makes my scrollview smaller and allows for it to scroll, but I need the footer to stay hidden under the keyboard still.
I think a work around to this would be to have override onConfigurationChanged(); in MyActivity that will detect if the keyboard has appeared, and if it has, push the bottom of the framelayout to be JUST above the keyboard, thus making the scroll view smaller, and allowing us to actually scroll. I am not quite sure HOW to do this though.
Here is what it looks like with the keyboard up, blocking the content. This would be okay IF the scroll view was scrollable, allowing me to see the rest of the content, however it will not scroll and the only way to access the content under it is to close the keyboard first.
EDIT
I was able to use the answer below, editing the Android manifest for
android:windowSoftInputMode="adjustResize"
and the first method using the code below
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
I had it adjust my views so the footer would be pushed way down below, then resize the layout holding the fragment to extend down allowing it to be scrollable still.
Okay, here's how I solved it.
The basic idea is that you have to:
Detect whether or not a soft-keyboard is showing,
React. Based on the detected information (is-soft-keyboard-showing), resize your layout accordingly.
There are two ways of achieving this:
to give your activity's root view a known ID, say '#+id/activityRoot', hook a GlobalLayoutListener into the ViewTreeObserver, and from there calculate the size diff between your activity's view root and the window size:
Customize your top-level layout class into one which overrides onMeasure()
And I would like to credit the above answer to this SO Post: how-to-check-visibility-of-software-keyboard-in-android, which I have found earlier on this particular problem.

Drop down menu from action bar - allowing drag and drop icons to be drawn to screen

as the title suggests I'm trying to add code to my app which allows the user to click on an item in the action bar menu which then unfolds a drop down menu (spinner class?) containing a few options such as lamp, tv etc. - each with an icon. The user will then be able to select one of these and drag and drop the icon (or an image representing the icon) to the canvas where it is then drawn. What is the best way to go about this?
If you're referring to the ActionBar overflow menu items, then you would have to take a look at the code for the ActionBar in the framework and extend it in your application, but that would firstly require quite a hassle and secondly would break compatibility when changes are made to the ActionBar in new versions of Android.
Also, this goes completely away from what the ActionBar is intended to be. You should only have actions in the overflow menu, not contain elements that directly interact with the Activity content. It's just wrong. Consider redesigning your UI so that you implement the requested featured inside the content view, not on the ActionBar.

Categories

Resources