How can I move a text box to the right or left in Android?
I want to make something like this:
I currently just used space to move it to the right but obviously this only works in a resolution that I was working on.
You can use
android:gravity="right"
You can also use left, end, start, centre, etcetera.
You can view the docs here
In this case you may also want to use:
android:width="fill_parent"
you can handle this on the xml side of things
Probably want to use a RelativeLayout with layout_alignParentLeft and layout_alignParentRight:
see : Aligning textviews on the left and right edges in Android layout which should be a pretty good example for you
Related
Does anyone know how to aligne two numbers on one line in android textview so one is aligned left and second one right?
Gravity doesnt help neither html.format...
Btw:i need to be able to keep changing properties of the text like colors etc..
I dont think this is supported by android. Maybe using justify could do it, but it only works on Oreo and beyond
https://stackoverflow.com/a/1293541/3885877
Else I would try a custom text view, where the 2 texts are aligned to the sides.
But I don't think you can achieve this very easy.
So i solve it by adding second textview
You could use dynamic strings with strings.value for this.
For example:
in strings.xml add this:
<string name="left_and_right_alignment">%1$s %2$s</string>
and in your class you can use:
getContext().getResources().getString(R.string.left_and_right_alignment, "left", "right")
Hope this helps.
I am very new to Android programming, but would like to change the style of my Switch View element so that it looks similar to the one that is displayed on the Android website:
and not like the one that I currently have:
I assume that because this is on the Android website it would not be difficult to change to this Switch style, but as I am new to Android development, I don't even have the faintest idea how to change this, and a large amount of time spent searching for the answer has not turned anything up as to what is causing my style to differ from the one on the website. Any help is welcome, thank you!
That's actually different enough that its going to be a pain- particularly the text on top of the switch instead of to the side. But lets ignore that and assume you only want to get the rest of the look, that you don't want words (words on a switch are a bad idea anyway, the word for "on" might be 7 characters in some language).
You can set the thumb drawable in xml via android:thumb. You can set the drawable for the background with android:track. If you want the side of the long area of the thumb to change,(its on top in your drawing on "on" and the bottom on "off") you'd need to change the thumb drawable when the state changes. The tinting of the thumb/track are controlled by android:trackTint and android:thumbTint.
You can see the other switch-specific xml properties at https://developer.android.com/reference/android/widget/Switch.html
I would like to see visually how much space each box takes with as little effort/changes to the code as possible.
I would like to know if it's possible to just put a line around the outer margins of the View or ViewGroup object.
Since it's just for debugging and styling I would like to also quickly turn it off, so I do rather make the changes to my code in one place so it's easy and quick to undo. Is this a default option I am missing? Somehow I expect this feature to exist already.
Here someone asks a different but slightly related question with not a nice answer for my case.
Here someone gives an answer on how to outline one View.
Border for an Image view in Android?
Code-wise you could follow the answer to the first link you posted and create a drawable with the name "developer_borders" or something similar and apply it to every view you wish to have its borders visible.
To easily remove it afterwards, you can right-click the directory of your project and click Replace in Path.... For Text to find you want to search for android:background="#drawable/developer_borders and for Replace with don't use anything. This will find every occurrence of what you are searching and replace it with an empty string.
There might be an easier option. Some devices have quite powerful Developer Options. "Show layout bounds" is what you want but take a look at the rest while you are at it, some are pretty awesome.
Simple aim:
To have default buttons in the navigation bar of my ActionBar with the text centre aligned. I simply want to use the default, simple way of:
ActionBar.Tab myTab = Actionbar.newTab()
myTab.setText("my tab's text");
What's the problem
I cannot find any simple way to do this whatsoever. You can't access the views (as ActionBar.Tab.getCustomView() always returns null due to it being the default view). There is no method that I can see in ActionBar, ActionBar.Tab, etc to get the current view, get or modify LayoutParams (especially Gravity). A visualisation of the problem is below (one line seems to work right, but double lined navigation buttoms definitely seem left aligned):
Unideal solution
Am I right in negatively thinking that the only way to accomplish this is to use custom views for all of my tabs, somehow guess / attempt to copy the default formatting for the tabs (as I can't find anyway to access these views) and assume / hope that the default formatting / font / style of ActionBar.Tab's text does not change any time soon?
Surely there has to be a better way?
AFAIK, there's no way you can access the Views in ActionBar. Using custom layout seems the only solution. However, doesn't Android align the text to center automatically? It apparently does so in all my applications.
please download the follwing example. it will help you. i am sure i take help from this demo.
https://github.com/JakeWharton/ActionBarSherlock
I want to create a popup that displays itself aligned to the right side of my element.
By default the showRelativeTo() implementation prefers to align the popup to the left side of the passed in element. It has logic for other locales to use right alignment
How can i trigger the popup to show aligned to the right by default in a normal Locale?
All the ways to do this are pretty hacky, but this discussion might be of some help:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3888
The end solution (and yes it is hacky) is to sub-class PopupPanel, and copy the whole 'position' method.
Within that method there is logic to right align, it only triggers by default if the locale expects items to be right aligned, but it is easy to add a boolean to for right alignment