This is a quick, probably yes/no question, but I'm trying to pretty up my xml and I'm wondering if there is a way to have a parent layout override the children's layout_width property? that way I can omit layout_width from every child node, for fewer lines of code?
Short: No.
For layout width is requeired property.
Related
i am getting "Set android:baselineAligned="false" on this element for better performance" while using LinearLayout, I know its regarding performance,but i dont know exactly why it is,please clarify me
If you are looking for a visual explanation like me, then you might find this useful.
When baselineAlign is enabled(i.e if it is set to true), then all the text in that line will be aligned to have the same baseline.
Note: By default, baselineAligned is set to true. (i.e. baselineAligned=true)
When you make baselineAligned=false, all it needs to do is to add new elements to the linear layout and be done with it. The app need not worry about where the baseline of other elements in the layout is.
See the image below for more clarity
android:baselineAligned/setBaselineAligned(boolean): When set to false,
prevents the layout from aligning its children's baselines.
So can take example with linear layout with horizontal child views having multiple TextView with different text size or different views like button there basealignment would be different and you cannot adjust it to have same basealignment if you set it to false
Reference
Update:
By setting android:baselineAligned="false" , you're preventing the extra work your app's layout has to do in order to Align its children's baselines; which can obviously increase the performance. (Less unnecessary operations on UI => Better performance) as mentioned here
If weightSum is not specified, Android will just add the weights of the children together. So, is there really a reason to use weightSum? Is there a situation where I shouldn't use it?
Is it more efficient than simply letting android add the weight by itself?
The important word in the reference documentation description is "single": "This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0." In this case, the sum of the weights of the children (in this case, only child) is different to the weightSum.
So you only need to use weightSum when you won't necessarily have the children filling the entire LinearLayout.
For example you can set weightSum = 3 for your layout, and weight = 1 for two children views. In result your views will range 66.6% of all place in layout.
Good luck!
I came through many examples in internet.I found that neither Relative Layout nor Linear Layout supports android:layout_gravity.By it I mean the views inside these layouts does not support android:layout_gravity attribute. So any one having idea which layout supports android:layout_gravity and how to use it in better way?
Children (that is, direct descendants in the View hierarchy) of LinearLayout do use layout_gravity (see LinearLayout.LayoutParams), but only on the "secondary" axis. So, in a vertical LinearLayout, center_horiztonal will work, but center_vertical will do nothing.
Children of FrameLayout also support layout_gravity (see FrameLayout.LayoutParams).
Keep in mind that the layout_* parameters set values in a LayoutParams object provided by the view parent. So a layout_* parameter will only have an effect if the parent view supports the parameter.
Actually if you use RelativeLayout you don't need to use layout_gravity.Better way to position your layout's elements are android. Here you can get a good explanation how to use RelativeLayout.
I have a LinearLayout which contains about 10 TextViews. I want the text of each TextView to be right justified. For now I have added android:gravity="right" for each of the TextViews, but I would like to have a better way out.
I would like to specify the alignment (or even style) of the all the children in the parent itself, so that all the children in the layout have the same style (instead of specifying the style separately for each children). Is that possible?
See the below article. You can declare styles in order to save yourself from headache
http://developer.android.com/guide/topics/ui/themes.html
Use a LinearLayout and specify: android:layout_gravity="right"
More info here: http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#attr_android:layout_gravity
I have a RelativeLayout defined in xml and I call the setContentView(R.layout.relativeLAyout) for displaying in Activity.
Now, if I want to resize this RelativeLayout then can it be done and if yes, then can someone let me know how?
The inner components can be resized relatively to the parent.
Is this actually possible?
Regards
Sunil
well if you use Eclipse, in the XML file, there at the bottom just switch to Graphical Layout.
and from there you can drag and drop payouts, Buttons etc :D
then in properties you can select add the pixels (200px ) on width/height
As to the inner components not resizing, make sure that both android:layout_width and and android:layout_height are set to fill_parent - then they should take up the space given to the parent.