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.
Related
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
Android provides the SlidingDrawer by default looks like below image -
Image http://www.gru.at/android/wp-content/uploads/2010/09/s_open.png
Can we customize this SlidingDrawer looks like semi-circle type with buttons included. For, example take a look at below image -
Anyone done the SlidingDrawer like above one. I've googled it. Didn't get any nice solution for this. Anyone has idea/example blog for this?
So make sure you have Gimp and 9-Patch at the ready for a lot of trial and error...
Then what you wanna do is...
Add suitable layout to hold buttons where the current ImageView Handle is, like Horizontal LinearLayout or RelativeLayout
Cut the id of the current ImageView Handle and add it to this new Layout you just added
add your buttons to the LinearLayout/RelativeLayout (you can test it now, the buttons and the handle should all slide open at the same time)
Now add Button listeners for each of the buttons
Set the SlidingDrawer to android:allowSingleTap = "false" (tit for tat, you cant have the single tap option anymore, just the slide)
Use a ButtonSelector.xml to have different layouts for buttons be pressed or not pressed.
This is the hard part. Edit the drawables for the buttons, and handle so that they will fit together nicely if the screen is huge, small, landscape, portrait. I recommend using 9-Patch in conjunction with Gimp.
Pat yourself on the back because you now have a totally sweet custom sliding drawer.
Make sure you post pictures and state any problems or issues you ran into as I have never fully implemented this, but I did get to step 6 to make sure it was possible.
Last but not least, Good Luck...
Thanks for RelativeLayout and FrameLayout These layouts makes my requirement comportable with what i need. I've done like below steps -
First, i've splitted the full image into three pieces. And, merge these images with FrameLayout And, gave onclickListner to my center of image(Because, it was contain that arrow marks up/down)
And, i've used the Animation for just to open that View as SlidingDrawer
These steps helps me lot.
I have created a shiny button in photoshop and now wish to use it for the background of a button on an android layout. Every time I change the buttons buttons background property it inserts the button but it does not fill the entire background but instead seems to push the boundaries of the button away from it as if there were huge amounts of padding! I have not altered the buttons padding properties either! I have previously been successful in filling the buttons entire background with buttons already created that I downloaded from the internet but I dont know if the were created in photoshop......however I did resize these buttons in photoshop and then successfully use them. Please see the image attached and notice the blue outline of the button whose background I am trying to fill! Any help is greatly appreciated!!!!
Try this: http://developer.android.com/guide/developing/tools/draw9patch.html
I need to create some custom buttons as shown in the image below
what is the best approach to follow?
thanks
Abdul Khaliq
That's a hard one. I made a lot of custom views, and the first thing I would thinking of is, made one Button with that above image, and handle onTouch by yourself so you can distinguish which area the user hit. There you can also change the state of the button, like changing the image to a bevel one e.g. when the left button is hit.
Can you imagine this ansatz?
You can place two transparent "invisible" buttons over the top of a background in a LinearView. Like two ImageButtons with a transparent png inside.
It is also possible to make this background animated when buttons are clicked using android animation class.
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.