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
Related
I want to have a page in an app have multiple buttons (in grid fashion) I was wondering if it would be better to populate a grid layout with buttons or manually add buttons to a relative layout, or if it even matters. I want each button to do something different so if using a grid layout is better how would I do this. I know you need to have gridview.setOnItemClickListener but that would make each button do the same thing (I think). Any suggestions would be appreciated!
If you have a fixed number of buttons, use a RelayiveLayout or TableLayout. If you have an unknown number of buttons and want to be able to scroll through them, that's the time to use a GridView.
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.
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
I am trying to create an UI just like the attached image!
How do we create these types of UI? Is it a ListView? And how do we get the arrow button on the right hand side? How should I start with such kind of layouts?
You can achieve that with a LinearLayout too.
Have that LinearLayouts orientation be vertical. Create such list items (it isn't related to ListView) using RelativeLayout.
Have the icon be an ImageView aligned to its parent left and vertically centered, the text would be a normal TextView which is to the right of that icon and vertically centered as well and finally another ImageView but this time aligned to its parents right and vertically centered.
These is the receipt.
It's a ListView, you should learn how to write your own ArrayAdapter and returns in the getView method the View you want to be each row of the ListView.
AnDroidDraw lets you create the layout online and then later download it on your device. http://www.droiddraw.org/
Create appropriate custom ArrayAdapter for this layout.