Is it possible to combine 4 strings into one Button with proper separation/styling between them?
For example,
http://i.imgur.com/swJzQ.png
Currently I have the values in a tablerow but I would like for it to act like a button.
Thanks.
EDIT: Figured it out.
Within the onclicklistener I added:
tr1.setBackgroundResource(drawable.list_selector_background);
where tr1 is my tablerow. (you will need to make the tablerow final for it to work).
I'm currently looking into a different list_selector color but this does the trick.
In one button, I don't think so but you can put your 4 String in a layout,set a selector in background and add a clickListener on your layout.
You can create an image that has the four strings correctly spaced, then put it in your drawables folder and apply it as a background for a button.
Or you can create a RelativeLayout with four buttons inside of it. Each of the four buttons has the text you want, and make them all go to the same place. You can space them evenly to where there is no empty room left between them.
You could make it a Custom ListView, it wouldn't be a button but you can still have an OnItemClickListener
Related
I'm making an android app where if you click on a Button, it will create a Textview. But my problem is that when the TextView is placed inside the GridLayout, the Button stays where it is. I want to move the button relative to where the TextView is placed.
Your TextView in the GridLayout is controlled by the GridLayout, GridLayout works in a different way as compared to other ViewGroups-afaik, an ex of gridlayout you will see that it uses column and row, so if you want to achieve what you want to achieve alter its column to the prefered place.
to be safe use a different Viewgroup
http://postimg.org/image/hvjzap2m5/
How should I create a button that has two different texts on both ends? Like in the linked image.
Use various spaces between the two texts and put the width of the button as wrap_content. If spaces in a normal string don't work, use Html.fromHtml("Text1 Text2"); as the string.
Edit:
Instead of using a button, use a linear layout with the style of the button, then insert two textviews inside that linear layout with gravity left and the other right.
I need to implement such a element - TextView of predefined size with white border line at the bottom. Inside of the TextView a button with predefined style and size should be. TextView shouldn'y be clickable and button should be. I see some possible solutions:
1) implement TableLayout and put all my buttons into the table's row. But there's not nice solution - my layout becomes too long. So I think about another solution.
2) make my element as a custom view. But the problem is that I need to use a lot of these elements through my app and I need use onClickListener to each of them. I know how to implement onClick() method for all items but how I can use singular onClick() method for each of the item? And how should I build this custom view - should it be extending from RelativeLayout, where TextView and Button with defined properties should be put?
I also thought about using for the button, but in this case my TextView will be also clickable.
Tell me please what approach is less complicated and more convenient.
I used another way if solving this issue. I put buttons and other control elements into the TableLayout with predefined TableRow style. In this case I do not need implement TextView and borders margins which I need I build with corresponding TableRow style.
I'm trying to build an Android app where I would like to display some Buttons in various places, as in the demo image attached.
The challenge here is creating the custom buttons and arranging them.
As for the custom Buttons, I guess I could achieve that using CustomViews or a simple button with a Custom Drawable as Background.
Are these the right points to start, any other ideas?
On arranging them, I have no clue how to achieve that.
As Android_Crazy and Closeratio have already said, a RelativeLayout is the most suitable option for custom placement of buttons in general. However, for the exact placement of buttons pictured in your example, a LinearLayout would work just fine.
In a LinearLayout you may place views under or above eachother (with android:orientation = "vertical", relevant for your example) or next to each other (android:orientation = "horizontal"). You can also add margin to your views to alter the horizontal position (layout_marginLeft or layout_marginRight) or the vertical position (layout_marginTop or layout_marginBottom).
As for the buttons' appearance, I always use custom background drawables, usually with a custom xml to add a different drawable for when the button is being pressed or selected.
I am learning Android by implementing a clone of Mastermind. I want to break up the screen (or View) into three parts: the board with the users guesses so far and feedback, a series of control buttons, and a series of buttons to pick the color of the next peg.
My instinct is to do this is a modular way. The layout files uses nested LinearLayouts (I know not the most efficient thing to do, but this is an educational experience.)
The "board" is a custom View where I do a lot of drawing with a Canvas. The buttons on the bottom are declared in the layout file. Notice the orange strip to the right?
Right now that is another custom View. I want to add a variable number of buttons to that custom View based on the number of colors the player can choose from. A button press would select the color for the next peg in the player's guess. (There are 3 versions of the game, easy, medium, and hard each with a different number of colors.)
So, how do I add a variable number of buttons to the custom View I am creating? Or am I approaching this in the wrong way? Should I use a prebuilt layout? If so, which one and how could I dynamically change the number of buttons in the layout?
Thanks for any help. Cheers!
You can do this in two ways:
Using a predefined layout and setting initially the property
"visibility" of all the buttons to "gone", then programatically you
can set the "visibility" of the buttons you need to "visible". The
"gone" property makes the button invisible and also not consumes
space in the layout.
Adding dinamically buttons to the main layout, first you will have to
create or "inflate" them.
The second options is more powerful, but also more difficult if you are learning.