Android. How to create button with two texts side by side? - android

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.

Related

What layout do I use for creating a form in android?

I need to create a layout exactly like in the picture. What layout can I use? If I use LinearLayout, I can't add the icons in front of the text fields without using so many nested LinearLayouts. With RelativeLayout, I don't know how to make the Textfields start always on the same height. With the Grid layout, I don't know how to put two Textfields in one row, like for phone and area.

Android - How do I move my button programmatically in a grid layout?

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

Layout realigned by dynamic text content

i'm trying to layout a fairly basic screen. it's just a details view screen after a list item click.
initially i'm looking to acheive a side by side stacked label value type of screen.
for example, where to the left of colon is static text and to the right of colon being dynamic values based on row clicked.
first name: john
last name: doe
last login date: yesterday
additional info: blah
i've started with a relative layout with a bunch of text views in it all positioned accordingly to acheive something like what i was looking for.
The problem arises when the dynamic data being displayed grows and stretches its enclosing text view. Of course the static labels don't grow and everything gets mis aligned...
I'm wondering if there is a different way of tackling this sort of layout...
i was shying away from stacking a bunch of horizontal linear layouts inside a vertical linear layout.
is table layout the way to go? i've read that "they usually aren’t the best tool for doing so, as they are derived from LinearLayout and not the most efficient of layout controls".
Yes there is. Use a listview with a layout predefined in xml. Use a simplelistadapter and pass it the dataset that you want to populate it with.
Edit
Here is a great tutorial:
http://www.vogella.com/articles/AndroidListView/article.html
For a simple form like you want to create I'd suggest using a TableLayout. It is simple to use. As you said the alternative to a TableLayout would be horizontal LinearLayouts in a parent vertical LinearLayout. Using a TableLayout will also automatically align the right side dynamic content for you. Everything on the right side will be treated as a column so if one resizes, they all resize to match.
In your particular scenario I would believe that the TableLayout would work well (although I have also heard similar issues of efficiency/performance). As long as the entire Viewgroup of this Activity isn't complex, I don't think the performance will be too noticeable.
If you are attempting to make the RelativeLayout version work, perhaps you can try this: Have all of your static labels are aligned to the left using android:layout_alignParentLeft and have each aligned to the top of the dynamic TextView they are corresponding to using android:layout_alignTop. This should keep the static TextViews aligned to the left while aligned to the dynamic view relative to it.
Now that those views are aligned, we can horizontally align the dynamic views to the longest static TextView using android:layout_toRightOf. From there, all the remaining dynamic views can also android:layout_alignLeft to this anchor dynamic TextView, or also align to the longest static TextView in the same manner that the anchor was. This solves the horizontal alignment of all the dynamic TextViews.
Finally, we can set that each dynamic TextView falls under the next, since the dynamic TextViews are our determining our vertical location within this RelativeLayout. Each view can use android:layout_alignBelow to chain the fields to align vertically.
I believe this should work for you and I can edit this post later in the day if you would like a sample of code.

Custom buttons arangement in Android

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.

Multiple EditText values in Button

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

Categories

Resources