Creating a custom view, best approach - java

How should I create this custom View? The actual slider doesnt need to slide, it is set once programatically and then just stays in that position. I was thinking that even if I extended ProgressBar I would still need to do some maths in order for the arrow to appear directly over a notch, so maybe drawing each Rect onto a canvas and then the thumb above in the correct place would be a better approach? Thanks in advance

Related

how can I make a Moveable and resizable canvas draw Android?

I need to create a Canvas draw (Or maybe another better way of creating this?) that has two separate points in a horizontal line. This is not the problem, but I need the two endpoints to move independently and also be "resizable" on user touch and drag. I've added a gif to better explain what I need.
What is the best approach for this? Can it really be done using a canvas drawing? Even better, I just care if the line resizes horizontally, I don't need it to change vertically at all.
I'm not putting here the end goal of this, simply because it's not the point of my question, but if it proves to be necessary I can edit and explain why I need this.
canvas can do any drawing you want, in you case, consider using seekbar or custom it

How to create a custom Android view? Using XML objects or a drawing API?

I'm trying to create a new view that would:
load an image
allow the user to zoom and rotate the image with two fingers while a "cropping box" stays translucent over the top while the image extends beyond the "cropping box"
with the end goal of being able to mark the rotation and position of the main image (so that later i could crop out or show the area within the cropping box)
I'm wondering if I can do this with an ImageView holding the image in the background and another ImageView holding the crop box on top of it, then using TouchEvents to move the image, would this work?
Or do I need to use some drawing API on a 2D surface?
I'm just really new to creating custom objects in Android that aren't just customized out-of-the-box Views.
What's the standard way of creating something like this?
Thanks!
Create a Compound View by extending RelativeLayout with two overlapping ImageViews in it. Then override onTouch event or override onGestureDetector interface in that newly created View.
Official Documentation: http://developer.android.com/guide/topics/ui/custom-components.html
Another Tutorial: http://www.vogella.com/tutorials/AndroidCustomViews/article.html

Creating a civilization game in java SWING best way to place the map on screen?

I'm creating a civilization game for a project just wondering what the best way to do it when it reads in a .map file with each line having characters inside of it representing a terrian
so for example t000="aaaaaaaaaaaaaaaaaaaaaaa"
would be the terrain for the arctic.
I'm just asking what the best method to place this into a view in java SWING, to view the map because what I'm doing right now is creating 2d array of jbuttons and placing the terrain image in those, but I'm thinking it would mess me up when I start adding sprites to the map.
Can anyone help?
Consider using ImageIcons for each terrain's background, and then perhaps creating a grid of JLabel, each holding the ImageIcon that corresponds to the correct terrain.
Edit
If your sprite is to remain on a tile, then add it to the tile as a component (just be sure to give the JLabel a decent layout manager). If the sprite is to move over the tiles, then it should be drawn in a different layer, either on the top level window's glasspane or in a JLayeredPane.

Android UI Design Suggestion

This is the scenario:
I have one image background set on an activity. On this background, a rectangle has been drawn (in other words, one image depicting a rectangle). I need to display text WITHIN this rectangle.
Right now, I have one solution in mind: since I'm going to optimize the UI for most screens (incl. tablets), I'm going to customize the main .xml layout for each screen size (multiple .xml layouts). Thus, I can manually set the place where the text area goes within the rectangle (+ its size).
I am most certain that this solution is NOT good. I'd like to hear some suggestions from more advanced developers. What would an elegant way of placing text over a background image showing a rectangle, so that the text stays within the rectangle's borders be?
Because I need to set particular positions for other UI elements (centered buttons (vertically/horizontally), I am currently using a Relative Layout.
By default if you have used dp as dimensional measure, your app should in theory work fine for all resoultions. Android by default scales the screen to fit different screens. AndroidDeveloper You just have to make sure that you have different images for resources (Rectangle image). There is another post in SO which you might be intrested to look into link
Cheers
RIchie

What is the best way to rotate several buttons in a jpanel around a central point?

I am working on a project in which I have a background image with specific points of interest. Each of these specific points will have a custom button class overlaid on it so that when I click the point, I'm actually clicking the button. However, I would like to be able to rotate the background image and have the buttons rotate with the image so that the custom buttons are still overlaid on the specific points. Any tips as to how I should go about doing this?
Are you actually wanting to rotate 4 different images and move them around the square, but always keeping them upright? Or are you rotating a single image so that after one button click the single image is on its side? If the former, then that can be easily done by using a container (a JPanel) that uses BorderLayout, and having four JPanels with background images and JButtons held in the container JPanel at the four compass points of the BorderLayout: BorderLayout.EAST, BorderLayout.WEST, BorderLayout.NORTH, and BorderLayout.SOUTH (although Java gurus prefer you use the newer constants, i.e., BorderLayout.PAGE_START). Then when a button is pressed, remove components and re-add but in a rotated order.
If you want to do the latter, then things get a bit trickier in that you'll likely need to use AffineTransforms, rotate instance to rotate the container, and you'll need to perform the same transformation on the point of the mouse press/click/release, so that the rotated buttons receive correct clicks. If the container is not square, things get even trickier still.

Categories