How to let user pick and drop, and resize buttons

Started by
5 comments, last by grumpyOldDude 7 years, 3 months ago

In the UI of my Puzzle Game I hit a problem ....

In Android xml layout, how do I add code functionalities that allow the app user to resize buttons (or other form widgets)?

Also what code in xml layout allows a user to pick a button from the menu and drop it at a position on the 'surface' they click? The pick and drop would be done first and then the resizing of the buttons (or other form widget) next

Though the xml code for allowing user to resize is the more important and the more pressing problem for now, but i will also appreciate solution for xml code which allows users to pick and drop

Initially it seemed like this xml code would be easy to find on the internet and I've been googling this for long but most of "user resizable code" I find are related to appwidget-provider class which is a different thing entirely. Other googling results don't threat it programmatically (xml coding) even though that was a key word in the search

thnx

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

Advertisement
Maybe I'm misunderstanding the problem but this doesn't sound like something you'd do with xml alone. You could listen for a button interaction with setOnClickListener(), track movement with setOnTouchListener() then move the button with setLayoutParams(). Maybe there are other ways of doing this though?

I've found solution that allows coding which lets the user/player perform drag and drop on menu widgets (or just buttons). Android has the APIs

setOnDragListener( ... ), onDrag(View v, DragEvent event), DragEvent.ACTION_DROP, and base class OnDragListener

these allows you to code drag and drop for the user

But i still can't find solution for the APIs(or code example) to allow user to resize buttons. Any help on this will be appreciated

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

Have a look at this developer page for dragging and scaling. Looks to have the answers you need.
https://developer.android.com/training/gestures/scale.html#scale

Many thanks @[member='Nyssa'],

I think I missed that because I relied so much on the key words 'user resize' among others while googling. Scaling or gestures never occurred to me

I'm also looking to see if this allows users to make asymmetric scaling along x and y of a generic widget (button)

A quick look through ... i'm not yet sure it allows that. Do you know?

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

Glad it helped. In regards to the asymmetrical scaling... In the following code grabbed from that link mScaleFactor is x and y scale. So you could have an x only and y only scale mode where you just keep the scale set to the previous scale for the other axis?

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.save();
    canvas.scale(mScaleFactor, mScaleFactor);
    ...
    // onDraw() code goes here
    ...
    canvas.restore();
}

Ah, that makes good sense! Many thanks!

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

This topic is closed to new replies.

Advertisement