Android image drag and move from one layout to another - android

Is it possible to move a ImageView from one layout to another. If i move an image from one layout to another i get an exception "java.lang.IllegalArgumentException: Given view not a child of xyz layout"
If i long press on a application icon, the app is moved from app list view to workspace. How does the launcher do this. How is it able to move the app icon from one layout to another layout ?

I would think of it differently. Instead of moving the actual view object, your layouts should be able to create and remove the same type of view based on the data that the view represents. It sounds like you're doing a regular drag/drop from one layout to another. When the drop occurs in the new layout, this layout should be aware of the data that is dropped and be able to create a new view based on this data. The original layout should be aware that it has lost this data, and remove the original view. Thinking in terms of the data that the view represents instead of the view object itself is probably the way to go here.

Related

Creating custom "instruction tips"

I would like to create a view which i could place beside a specific function on the screen as instruction. This "instructiontip" thing will show automatically according to some rules.
The advice I'm seeking is about the way to put such a view anywhere on the screen above all else and not affected by parent type, fx. if added dynamically to a view which root layout is LinearLayout (vertical), I of course don't want it to be places under the last element. I'll place it using coordinates on screen and would expect it to show exactly there.
Here is a design shot for impression:
I keep thinking that there must be a better way of doing that then just adding it and hoping it will show in place.
Activity.AddContentView is a good way of adding such a view above everything else without affecting whatever is beneath.
The only downside is that you can't remove this view after you added it.. but you can hide it if you need to.

How to make RecyclerView with multiple ViewHolders so that one ViewHolder is also controlling another ViewHolders content

I'm trying to implement horizontal scrolling view and managed to actually implement it using this tutorial. Horizontal RecyclerView tutorial
It has it's problems on focusing but at least it works.
Depending use case i have about 2-8 different images to view.
Now my problem comes that my layout is looking like this.
Current layout There is also other fields which isn't included in image.
Now images comes to image field and text would come to text field.
I would like to make those so that when image is moved also text will move at text field but not another way around. When trying to move from the text field it doesn't do anything.
in that tutorial both text field and image field are in same layout but i have separated those and also have that third field which isn't part of the RecyclerView. And adding more to this mess i also have button and when pressing it will change to next image on image field at below layouts.
So what would be good approach to make this to work??
http://smstuebe.de/2016/06/12/mvvmcross-recycler-templates/
You must create an interface to return proper layout for each of your element. You must define all the type of layout in the template selector

Android different media in one view

Ok I do have a question regarding how I would implement this function:
I am creating an application, and in one activity, I want to display several information in the upper half of the screen. Now if I want to display an image, I chose ImageView, if I want to display text, I use TextView, and so on. The user choses what do display in the activity that comes before the display-activity.
Now my question: What kind of View do I chose for this? I was thinking about a WebView, to display images or text. But there is also a chance that I have to display a player for a .wav-file. Does WebView also provide this function? My Problem is that I cannot just say that I chose an ImageView, because it displays no text, and so on. I need a container that can display everything.
Or is there a possibility to overlap like 3 different containers, and activate only the one that I need?
You can have all 3 views in the layout and use Visibility.GONE to hide the ones you don't want. Or you can dynamically add a insert a view at runtime. A simple way to do this second solution would be to put a placeholder view there in your XML layout, and at runtime remove this view and dynamically insert your desired view in it's place.

Android view animation: replacing view by itself

In my android app, I have a notion of "trails": a sequence of objects that the user can navigate. The same view, naturally, is used to display all objects, just updating components (texts, images, etc.) when the next object is to be shown.
Now, I want to animate the transition between objects: when the user navigates from an object to the next object, I want to use the slide animation from right to left (and the other way around). The issue is that I don't have two views to animate between - only one view. Therefore when I try to animate displaying this view (when the next object is to be loaded), the visible view disappears, I get a blank screen - and then the view slides in from the right.
What I want instead is to have the existing view to slide out and be replaced by a new view (same View but with different content) to slide in from the right.
How should I go about it?
Looks to me like a combination of LayoutTransition and GestureDetector. You might even a ViewFlipper in there too.
The LayoutTransition has an animation feature you might want to look into.
I haven't been able to figure out how to use LayoutTransition in my case, so instead of having my View, I replaced it with ViewFlipper containing two copies of my View. When I need to replace the view with another, I keep track of which of the two is currently displayed, then update the other off-screen and then use standard "slide-from-left" and "slide-from-right" animation with showNext(). This is more complicated than I really wanted it to be and uses more memory, but it does the job.
The solution turned out to be very simple: ViewPager. I provide PageAdapter, which returns two similar views (same layout, different content) and ViewPager takes care of the rest. If I wanted to disable the swipe page changes, all I had to do is extend ViewPager, override onInterseptTouchListener and return false.

GridView in android

I have a gridview of images in android. When i click any item on it, i want to show a new set of items over it. This is the screen shot .
Can this be done using gridview? Also what should be the type of view which must come over the gridview? The background should become preferably faded.
I am not so sure if you can achieve the second view using a grid view. In the grid view AFAIK you don't have any option of specifying the location of the grid elements. It just arranges it from left to right and wraps around.
But here is how I would do it -
First view can be done using the grid
view, as you already know/done.
For the second view since you want the the first view to remain in the background, there are two ways to go about this -
First option
You can use a dialog, you can create your own custom dialog which has makes it translucent.
In this custom dialog you can add further elements like images.Custom dialog example. For details on how to make it translucent you can look the sample app in android sdk.
Second option -
Use a layoutInflater. Put all your views into it.
You can display one view on top of another using the visibility attribute of the view. Layout Inflater

Categories

Resources