Here's the basic UI i intend:
There is central circle:CENTER. As the view is rotated, new circles:NAME are generated on the circumference. The circle at the top is a newly generated circle, i.e. if an already generated circle passes the top it fetches a new name.
I don't know the Android API well enough yet, so can someone point me in the right direction? What classes should I look at? How can I create that sort of pathing? Do I generate circle programmatically or have the views already in the xml layout but invis?
Thanks.
EDIT: Currently I'm working on the custom views that will be each circle.
I think you could do it by extending AdapterView. I would start by looking at the source code for it and some of its decedents to see how they implemented them.
The functionality you are after I don't think is very far removed from a ListView or some of the other simple Adapter ready View widgets.
The main difference is going to be your onDraw() method, you'll need to override that to draw the circles for you. Whether you make the circles programmatically or define your own views in xml is going to depend on how you want to appear visually.
I don't have any sample code for the rotation effect you are after but surely it can be accomplished with a canvas and some geometry.
Once you've got the AdapterView built you'll also probably want to subclass an Adapter to hold your names and override its getView() method to populate the names into the circles for you.
If you have not ever implemented any of the ViewGroup widgets I suggest you start by exploring some of those. ListView, GridView, etc.. Learn how to use it with an adapter and some data to create the dynamic layout. Once you have a good understanding of how to use the ones that are already built then start trying to tackle the one you want to make.
Related
I am new in the corporate world & from design perspective please correct me if I am doing something wrong here
I am fetching images from Flickr API.
GOAL: Show these images in two different type of view, grid view and listview. Which can be switch through the slide.
So I am using a View pager with two fragments and both of these fragments has separate listeners. So when the response came from Flickr both of these listeners are notified.
In my opinion, this saves two times calling of REST API, but I am looking for even more efficient design or flow through which
Using single listener
Rest API should be called once
Result should be store (Just in ArrayList) and share to both of views
May not choosing two separate fragments
Avoid creating Adapter object two times
Image should be stored in cache
Any tweak or suggestions will be helpful a lot, please comment if you don't understand any part or whole question.
For above problem, the tweaking you are thinking is almost right. Other than below:
What I believe you must create two different adapters to have more control over different views. For example, you might want to show with scale type crop center for an image in list view but scale type center inside for an image in grid view. There might be the different type of thing you may want to perform. So, it's a good practice to make two different adapters, to make the code more manageable.
Again the same goes for the fragment, see if actions in both the fragments are same or can be done with single variable passing. Then only go with a single fragment.
Rest of the things are perfect.
I have a game which uses a RecyclerView to create a horizontal "Stages" view. When the player passes the current stage I want to add a simple hop animation to the view containing the "Stage" the user just passed. I've tried using normal Animations, but haven't been able to get them to work correct.
The documentation of the animateChange method of ItemAnimator sounds like it's a good place to do this, but I haven't had any luck finding good documentation on how to implement a custom animation here.
I'm looking for advice, pointer to documentation on how to create custom animations on item change, or a solution. Any help would be greatly appreciated.
I was able to accomplish what I wanted by using a CycleInterpolator
For some reason (that I can develop if you want/need) I have to redraw all the chart periodically. So, I use removeAllSeries then addSeries, plus removeAllViews then addView. It works but the problem is that addView adds the view not by simply refreshing all pixels of the tablet but with a sort of "animation" that puts firstly the View a little bit (2 or 3 pixels) shifted to the right and then it takes the right place. The consequence is that, everytime I redraw my graph, it looks as if there is a "vibration" (it's not fluid).
Do anyone have some issue? Could this undesired "animation" be related to how the addView method is done?
there are three ways:
redrawAll() method. Maybe it is protected, but you can overwrite and
make it public
change the data in series (appendData or resetData). The Graph will
automatically rerender.
removeAllSeries + add new series. No need to call
removeAllViews/addView. Take a look at the GraphViews-Demos project,
there is an example about that.
Cheers
Thank you for your answer ! I actually just simply overrided the ValueDependentColor() method directly in my main activity. The color depends on a timer. So, when I reset data after x seconds the graph rerenders as you said in your "2."
I need some valuable advice from you guys...
I have a UI where I have to drag objects from one view to another.
I have a rough sketch of this UI below
I think I have to create a custom view for this. I have to drag a square and a ball from bag 1 and bag2 [both bags are scrollable, can contain 10 to 60 items each] and drop it to the closet one by one. and later I have to find the number of items in the closet. The items in the closet must be arranged in a well maintained fashion [may be ...like 6 in a row].
Where should I start?
How many custom views should I use?
Is there a simple and effective UI solution for this?
Happy coding..!
I would suggest a design with three different GridView objects laid out inside a ViewGroup that supports dragging objects from one GridView to another. The objects would be custom ImageView subclasses so you'd have a place in code to support a drag-and-drop protocol of some sort and because you'd likely want to associate some data that is specific to your application with the objects being dragged.
As for the drag-and-drop protocol, you could consider an adaptation of the Android Launcher drag-and-drop framework or the current drag-drop classes described on the Android developers' website. I don't have much to say about the current drag-drop classes. I have not tried them yet, but understanding them is on my to-do list. However, I have done an adaptation of the Launcher code, and I have written it up on my blog and posted demo apps and source code there. See Drag-Drop for an Android GridView.
With the framework that originated in the Android Launcher, you have a good set of classes and interfaces to work with. Some of the objects include: DragLayer, DragSource, DropTarget, DragController, DragView. The DragLayer is a custom ViewGroup within which all drag-drop operations occur. It delegates handling of all the touch events to a DragController, which is the object that does the actual moving of objects around on the screen. As it does so, it interacts with DropTarget objects to give the user visual feedback that something is being dragged and that a place to drop something is available. A DropTarget is an object where something can be dropped. A DragSource is the interface for objects that can be dragged within the DragLayer. The Launcher framework is a good one because it gives you a way to think about dragging and dropping and how you want to divide up the responsibilities defined by the framework.
The reason I suggest GridViews for your problem is it sounds like you are thinking that way already. The closet has "maybe 6 in a row" so that could be a GridView with one or more rows depending on how screen space you have. A GridView would also work for the container that holds the squares and circles. If that is a good fit, you could study the code in my drag-drop tutorial and see if that makes it easy for you to move objects from one GridView to another.
In my demo program, I ended up with a custom subclass of ImageView that I called an ImageCell. These are views that are on the grid. An ImageCell allows objects to be dragged from them and onto them. For awhile as I worked on the tutorial, I had a custom GridView class too but ended up with the standard GridView. It sounds like you'd want a custom GridView because it sounds like being in the closet is different than being in the other sections. Having it gives you a convenient place for the methods you have not thought of yet.
I hope some of these suggestions prove useful.
Depends on the Android version you are targeting. For 11 and above you can use the built in drag and drop functionality, otherwise you are pretty much on your own. I would normally advice you to implement some sort of a long press action that might even allow you to select multiple items and move them in batches, which would be a really simple thing to implement.
If you really need DnD you should check out this example, it should give you some idea on how to make your own implementation.
I think that bag1, bag2 and closet can be three instance of the same configurable custom view (let's name it CustomBagView).
CustomBagViews should be responsible for displaying items (using a gridview of imageview for example).
I think those will not need to handle drag & drop directly but they should support
removing and adding elements
provide a setOnItemTouched(Interface_class) callback setter.
Then you will need to code a Container custom view (let's name it BagContainerView) that will contain the three bags and handle the dragging & dropping from the bags.
You will provide a handleDrag callback to each bag using CustomBagView.setOnItemTouched, then track the finger motion in it.
When the dragging finishes, you must find where it ends, locate the right 'customBagView' and ask it to add the item to its list.
I'm trying to get this effect on a list item in a list
https://ssl.gstatic.com/android/market/com.whatsapp/ss-2-320-480-160-0-a637ec45d9d24eb0f50c610657654007223dbe19
What do I have to do - override a LayoutContainer and implement my own onDraw method?
I'm not very good when it comes to graphics/drawing (in code) so can someone give me some starting ideas on how to implement this?
Thanks,
In general it would be much easier. define a 9-patch that can expand that is the background "bubble" and will serve as the background tot he listviewitem. you could dynamically add views (images, textviews, etc) depending on content, or if your needs are simpler, you could just have a single listviewItem.