I have a very simple widget that has a background image of a speech bubble and an imageView that contains a character standing next to it (as if he is saying something).
On top of the speech bubble i have a textView in which i show some text.
Basically all i want to do is so that when the user clicks on the character the image changes to show an animation of the character.
I did a simple app that animates an imageView (using the animation-list xml) when the image is clicked and that worked fine. So i was wondering if i could achieve the same thing with this widget.
I have seen some examples where by you can click on a widget (be it a button, image, whatever) and you can then load a config layout however i simply cant figure out and i cant find anywhere if what i want can be done.
So basically what i need to know is:
1. can a widget have an animated imageView
2. What do i need to do so that when the imageView is clicked it loads the animation?
Can anyone point me in the right direction please?
Thanks in advance guys!!
Have you tried to use LayoutAnimation? See the related question here:
Android Widgets: Animations on RemoteViews ?
Related
I want ImageView start expanding to fit the screen (it would be great including some animation with) when ImageView is clicked. Although i've found a great sample to show.
This is the default scene:
and when user clicked in the image:
How can I approach this solution? Any code example will be appreciated.
In order to view the image in a full screen after clicking the image. We need a create a new Activity (or) dialog fragment which makes our work easier in design and coding aspect also. To achieve this we can directly use intent and pass the url to the full screen activity and from their we can use a image loader to download and show it fully. Remember in your case background of the fullscreen activity should be transparent.
If you want to do some animation for this transition means, I would recommend you to use the shared element transition for this. The following link will help you to achieve this,
Link 1
Link 2
Hope these links will guide you in achieving your requirement :)
I'm still kind of new to android. I'm writing a Tic Tac Toe game as a bit of practice. I'm trying to figure out how to replace views when I click a button. I have 9 buttons in a GridView. When a user clicks one, I want that to change to a non-clickable TextView and back to Button when a user click's the reset Button at the bottom of the screen.. I use a flag to keep track of player's turn so it'll know whether or not place an x or o. Is this even possible or am I stretching here?
You'll soon find that there are really not that many things that are stretching it for Android.
This is certainly possible. For each grid in your GridView, put in two elements - the Button, and the TextView. Change the visibility of each. In other words, you don't actually replace one with the other - you just hide one, and show the other.
So you'd have two items like this:
<Button ... android:visibility="invisible"/>
<TextView ... android:visibility="visibile"/>
And have both of these match_parent, so that they fill each grid and are basically both on top of each other.
To change the visibility in the code:
button1.setVisibility(View.INVISIBLE);
textView1.setVisibility(View.VISIBLE);
I'm trying to give you as little actual code as possible so you play with this and write it yourself, but this should definitely put you in the right direction. Let me know if you need more guidance though.
You can do it two different ways
You can put both a button and a textview in each grid and interchange their visibility when you click on the button. For this, you can set the button and textview properties from the xml layout and you dont have to do much programatically
You can use a button alone and just change the look by changing the background drawable at runtime. Then you can make it unclickable by disabling it or changing its focusable property to false
You can even use an imageview and just change the drawable src and disable it on user click. Android is quite flexible and this is not even a stretch. If you give a little more detail of the specifics you want to achieve, I could advise which solution will be best fit
I have two png-images for the pressed and released state of a button. I'd like to build a button that accomplishes the following:
Has no background/border (only those two images visible)
Does not highlight with a blue rectangle when clicked (only by cycling through those images)
Does not get activated, when the user clicks on a transparent part of the image.
As you can see, the button is not rectangular, so the last point mentioned above might be tricky.
I already tried to use an ImageButton and managed to meet point 1, but I failed at point 2.
Is there another View I can use, that does the work for me? If not, could you hint me what techniques I should look into to solve this?
Just use ImageView
One image set as background, second as src.
And it resolve all your problems
[Edit]
for third part- follow this https://stackoverflow.com/a/8086317/3811198
in short
Use a TouchListener instead of ClickListener
Inside the listener, if the event is MotionEvent.ACTION_DOWN, get the touch coordinates
Check the image's pixel at the coordinates you obtained earlier; if the pixel is not transparent, consider the button was clicked, otherwise ignore the event.
If you use setBackground = "#0xxx"; on button in xml file the borders will desappear. Basically making it transparent using alpha
android:setBackground = "#0AAA"
I made an app in Android, in which I put twelve buttons. When you click on a button, it will show you an image on the button. It's like an image puzzle game, with two buttons containing one image.
If the images match, then the game continues, but if the images do not match, it will disappear.
The only thing that I don't understand is what code and logic I should use if the image does not match and it will disappear.
Please help, thanks.
If you want to make something disappear and take up no space, you can set its visibility to 8 (which is invisible). Here I'm making everything inside a layout invisible.
LinearLayout buttonbox = (LinearLayout) findViewById(R.id.storybox);
buttonbox.setVisibility(8);
You can change the visibility of any kind of view. Here's the documentation.
I am trying to make a really easy xml layout and I can't seem to get it to look the way I want.
I attached a picture of what I want it to look like:
Basically, I have a static background image in my imagebutton at the top. Below that I have a picture the user snapped in the Photo Box. I assume I need an image view for that, but would it be possible for me to instead pass the pic to the background of an image button too so I can make the size easier to manage?
Based on what the user chooses in the options before this layout, an option photo is shown based on what they select. The photo would display to the right of the centered image, if that option is selected.
Below that would be a centered text view, with another separate one below that. Finally, I would have two buttons on top of each other at the very bottom.
Could someone show me a good way to get this layout and also tell me if it is possible to take a picture that is snapped and make it the background of an image button - or if that is a bad idea?
Thanks so much!
Seems like for the most part, you just want a simple LinearLayout. For the part with the photo, you could use an embedded LinearLayout or RelativeLayout.
As for the picture - you can easily set the background of any view or view group to any image (any view has an option to set the drawable for the background).
The only thing you should consider - for the purposes of making the UI more intuitive - is to slightly modify the image for the different states (focused, selected, etc), so that the user gets visual feedback when selecting the button via the trackpad, or when clicking on the button. A "drawable" has built-in support for multiple images for each state.