I am designing something that will have a homepage close to the Google+ android app.
I'm having trouble figuring out the best way to do this? Should I create a button with text and set the background as the image? Should I create an image with the text already programmed in the actual picture or should I program the text and picture to be buttons.
Any suggestions from you guys on past projects?
You can use a Button with text to whatever you like and then place the image for that button above the text (using android:drawableTop)like so:
<Button
android:id="#+id/imageButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Photos"
android:drawableTop="#drawable/button_image" />
replacing buttton_image with your actual image. If you want the image in a different position (i.e. below text etc) use:
android:drawableLeft
android:drawableRight
android:drawableBottom
This would be how I would and do do it...
Since I am a newbie in android development I may be wrong but I suggest why not use a Grid View with each grid item haaving a textview and imageview.
My suggest to layout:
If you want to try something new in Android 4.0 , you can try GridLayout to layout , it can reduce the complicate of the nested layout , check out the blog about GridLayout:
http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html
You should write Buttons this way: http://developer.android.com/resources/articles/layout-tricks-merge.html
I normally use RelativeLayout but this is not important.
Write a class myClass extends RelativeLayout and inflate the XML with
LayoutInflater.from(context).inflate(R.layout.myCustomLayout, this, true);
I think this is best practice by Google.
use a regular button and set the android:drawableTop="#drawable/icon_...." value
Having the text burnt into you image is most certainly not the way to go.
One option for you is a GridView. You could also do this through a combination of Image button and scrollview. In my opinion, GridView is best and involves the least amount of code with most flexibility.
Remember that you can replace the button's background image with a state list drawable.
Related
I have a image "myXmlImage" in my .xml file
In the .kt file, I want to paste another "newImage" image as well as a little text "newText".
myXmlImage.setImageDrawable(newImage.drawable)
myXmlImage.imageMatrix = newImage.imageMatrix
So far it has been working very well and the new image is in place.
I'm completely stuck on how to paste the little "newText" into it
Any ideas will be greatly appreciated, thanks in advance.
Perhaps there's more than what you've described here. But if those are really your only specifications, then what you're asking for is really easy.
I'm assuming that your xml file has a root of ConstraintLayout. If it doesn't, then you're going to either want to change it or at least wrap your ImageView inside of a ConstraintLayout.
Use the layout editor to place a TextView inside of your ImageView (NOT AS A CHILD; when I say "inside", I mean spacially inside). If you haven't used the layout editor very much, it might take you a couple of tries to place the TextView inside. Don't just drag it into the ImageView as if it were a child. Drag it and drop it under the ImageView inside of the ConstraintLayout and then use little circles on the sides to attach it to the sides of the ImageView. Don't forget to set the text of the TextView as "".
(I'm not actually sure if this step is necessary because I don't know what the default background of a TextView is, but I do it out of habit.)When you're done placing that TextView inside of the ImageView, go the code of your xml file and use android:background="#00FFFFFF" (or maybe somewhere in your project you have either a transparent background drawable or a transparent #color that you can reference by name).
I'm sure you know the rest. Just give that TextView an Id like newtext and inside of your activity retrieve the view: newText:TextView=findViewById(R.id.newtext). And then set the text: newText.text="new text".
I suspect I'm going to have to do this the hard way, but here goes
I have this:
<Button
android:id="#+id/favouritesButton"
android:layout_height="wrap_content"
android:layout_margin="5sp"
android:text="#string/favourites"
android:drawableLeft="#drawable/shopping_basket_90x75"
android:enabled="false"
style="#style/BtnBigGreenLeft" />
Which gives me this
What the client wants is this (different drawable image but you get the idea)
Is this possible, or do I have to break it out into separate elements to get it to work?
Yea just break it down. It will solve you many future problems with any other solution.
And make the Linear layout the wraps it all clickable.
Sorry for my english.
If you want that all the picture will be clickable you can fix it simply
but if you want that only the green area will be clickable it should be harder
Sorry for my english again.
if you want whole thing clickable you only should to change the picture in the Paint program on your PC and change the correct pic to the new pic that you made and that it.
I hope it will halp you.
I think that you cant do this in one button.
Try to use the ImageButton on the image and break it down to 2 diference buttons(button and imagebutton) or just use the Paint program on your PC and put the image on the ImageButton background (the second I think easyer).
I've been working on my android calculator and i can't seem to insert an image instead of text on a button. For example sqrt I don't want to have sqrt written on my button i want the image of the symbol on it, the same goes for x^y and alot of others. I have my custom background of the button working just fine. Thank you for your help in advance :)
EDIT:
Thats not what i wanted i did manage to get my custom button and thats fine. On my button since its a calculator button i have android:text on it saying sqrt. I want to remove that and insert another png on my button showing the symbol of the square root instead of that text. Thank you for quick responses.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/imageName"/>
You can have both text and image (or no text) when using the attribute drawableTop, drawableBottom, drawableLeft and drawableRight.
And for positioning the image how you want, consider using: paddingTop, paddingBottom, paddingLeft and paddingRight.
You can do this by ImageButton:
<ImageButton
android:id="#+id/submitEmailButton"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_gravity="right" android:layout_marginRight="15dip"
android:background="#drawable/ic_submit" />
Here ic_submit is the image you want to show as a button.
I used this tutorial and it worked perfectly for me: http://www.mkyong.com/android/android-imagebutton-selector-example/
I haven't seen your code but basically you should remove the "text" tag from your xml and it should appear the image without text then.
I don't know if that's exactly what you were looking for or not, but I reccomend you to follow the tutorial and for sure it will work for you ;)
There are a number of alternatives you can try to implement to build your SQRT button:
draw the button as a 9-patch drawable so your SQRT symbol won't get distorted;
use a RelativeLayout with a button inside and implement a selector
You can simply set background for the Button and keep its text blank.
I want to create icons as something like this image or something like on the homepage of quickr. If I use custom gridview for this as in this (of course in my case I need the text below the image ), then adding listeners to that would be difficult I guess. Should I use buttons for that with the image and text below that provided the background is transparent? If so which layout I need to use? Or is there any icon view facility in android like other views such as button and imageviews, so that we can modify as per our requirement.
You should use button for that.
<Button
android:id="#+id/btnIconName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/iconimage"
android:text="IconTitle" />
For showing icon you should use android:drawableTop and for iocnTitle use android:text
Property.
I hope my answer is helpful to you.
GridView will be the best option to do this and why dont you ask your graphics guy to add text with image.
The question is pretty much exactly what I want, lets say i have this text:
"{W}, {T}: Tap target creature."
I have to replace the {W} and the {T} for 2 tiny little images pretty much the same size of the 3 letters(in case {W} and {T})... Is that possible in some way?
Just to say, the TextView is inside a Listview...
the Position for {W} and {T} are not always the same...
the images are in my resource...
The one workaround you can try is to place your TextView and ImageView inside a FrameLayout, one on top of the other. Now when you want to change them, just make one of them invisible and initialize the other. This will probably work. Hope this helps.
Did you try the attribute drawableLeft of the text view? But since you have two images, you will have to use a single image file which consists of both {w}{t}. so you will have to put the images with all combinations of {w}{t} in your resources.
then use the following method in your code:
textView.setCompoundDrawables(leftDrawable, null, null, null);