This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do you rearrange buttons where you want them in Eclipse?
Hey guys I am having trouble with placing my buttons in my XML layout. I already have a background and was just trying to put 3 buttons near the middle and thats where I'm having trouble. I know about center gravity and all that but could you help me? Also, If I made my own buttons can I just import them using the image button thing, or is that not right? Thanks for the help!
You can rearrange elements of your layout by editing the XML directly or by dragging and dropping in the outline view or the graphical layout view (I find the latter harder to do reliably).
To use your custom views, click on the "Custom & Library Views" button in the graphical layout palette, or just type in the fully qualified class name as the view tag in the XML.
Related
This question already has an answer here:
Should I inflate a layout or programmatically create it?
(1 answer)
Closed 9 years ago.
I've simple dialog with only one ImageView, and im using it frequently in my app, and Im wondering what is faster to load and showup, create layout in XML or make the same thing in code.
EDIT
I ask about theoretical knowledge in this point, and I cant find any useful info about that on Android Dev sites.
Theoretically in my opinion, coding the layout is faster than inflating it from xml, because inflaters need to map the layout by it self, and link id's to each other, but in code you will give the viewgroup (lets say) the reference of the view it self, there is no need to lookup it in the xml.
don't forget the step of converting the xml into java elements (views)
No difference, but if you have only one imageview make this layout in code
For performance, there is no noticeable difference.
But for maintainability you want to separate functionality and layout, hence it is recommended to use the layout XMLs.
No one is necessarily faster.
It will be the easiest to define the layouts in xml though, and the xml option is there as a way not to have to define buttons and ui components in java.
Also, if you define views in java, you will end up adding them to your blank xml layout's viewgroup
( ei. adding your button to the layout)
This question already has answers here:
Is it possible to have multiple styles inside a TextView?
(20 answers)
Closed 9 years ago.
I am currently working on android project where I want to have a text view that contains two lines of code. I know I can just put a new line character in between to make it on a new line but I want to do a bit more than that.
Basically what I want achieve is on the first line I have text which uses the normal text design and on the next line the text will be styled differently, i.e. smaller and slightly different font colour.
I've tried searching for this and can't find anything anywhere.
Thanks for any help you can provide.
Option #1: Just use two TextView widgets in a vertical LinearLayout
Option #2: Use Html.fromHtml() to convert an HTML representation of what you want into a Spanned object that you can pass to setText()
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Eclipse with Android layout's main.xml?
I'm trying to design a layout, statically. I wrote an xml file and I'm, now, modifying it under Graphical Layout mode. However, when I switch back to the XML Editor and scroll through the code, the code seems to change automatically. I even tried refreshing the file from package explorer but still in vain. Now, I know this issue since long but had neglected it. How to avoid such a thing from happening? Thanks.
my advise is don't do any modification under the Graphical Layout only inside the XML Editor, the Android support from Graphical Layout is a bit lame , i do all my modification from the Xml Editor
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
add and remove views in android dynamically?
In Iphone, the view is added or remove by using addsubview or removefromsuperview.
What about in Android, how do you add or remove a view?
fundamental questions, I am trying to clear up my concepts.
thanks
You seem to understand programmatically adding and removing views in iOS
In android, you cannot necessarily add a view to a view. You will need a subview of the Class ViewGroup (RelativeLayout,FrameLayout...) that you can add views into.
You can use
void android.view.ViewGroup.addView(View child)
void android.view.ViewGroup.removeView(View view)
There are more ways to add and removeView, but the important part is that you look up the reference for ViewGroup. Android layout is a whole different cup of tea compared to iOS layout.
Hey guys I am having trouble with placing my buttons in my XML layout. I already have a background and was just trying to put 3 buttons near the middle and thats where I'm having trouble. I know about center gravity and all that but could you help me? Also, If I made my own buttons can I just import them using the image button thing, or is that not right? Thanks for the help!
PS: Also, there is a big white box around my button. How do I get that to go away?
I posted this answer to your duplicate question, so I'll also post it here. :)
You can rearrange elements of your layout by editing the XML directly or by dragging and dropping in the outline view or the graphical layout view (I find the latter harder to do reliably).
To use your custom views, click on the "Custom & Library Views" button in the graphical layout palette, or just type in the fully qualified class name as the view tag in the XML.
If you use Image button you can set your custom Image to src property or background property. If youi chose src you should add android:background="#null".
But I would recommend to use background property while if you use 9-patch png (who knows maybe tomorow you will use 9-patch) they would not stretch if you set it in src.