This is an example of my activity with element fixed and automatic margin:
But when use fragment:
Its possibile to set margin on fragment?
In the fragment container in your activity xml, set padding to the container. In your specific case, set it to the ViewPager.
example:
android:padding="10dp"
Try providing margin to the container you are using to contain your fragment.
for eg. if you are using the framelayout as a container give margin to the frame layout.
Related
The linear layout in android is like this...
Layout available
But I want a layout that will move the inner widget down instead of forward like this
Layout I want
there is no layout in Android, which can do such replacing, but you can use Flexbox lib from Google
If you want to only use linear layout then you can do nesting of 2 linear layout
in 1 : orientation will be vertical, and horizontal in other
To make it more easy, use relative/constraint layout.
When I create a layout for my fragment or my custom view I must define layout_width and layout_height. When I use this fragment or view in another layout, I must also define layout_width and layout_height.
Let's say that the root element of my fragment/view layout has layout_height="match_parent" and when I use this in another layout I have for example <fragment layout_height="wrap_content".
In this case the layout_height element is basically defined twice, once in the layout of the fragment/view itself and once in the layout where I'm using it, but with different values.
What happens to the value of layout_height of the root element of the fragment/view in this case? I don't understand how this works... does one override the other?
when you are using match_parent for parent layout it matches the parent width/height.Now when you are using another layout inside this parent layout
1.if you are setting wrap_content it will not totally use the height/width of parent as it's set to wrap_content
2.setting child layout width/height to match_parent then the child layout will stretch to entire parent limits
How can I achieve this layout?
Use a FrameLayout that act as a parent of a LinearLayout( say layout ll_par) & an ImageView..In your ll_par add your two remaining layout .& remember put the Imageview as the last child of FrameLayout & set its layout_gravity to right|center_vertical & give some margin to your Imageview according to the need ..
I am developing an app with an activity with member reactions on a hike event. The reactions are the yellow "balloons" which are made using a LinearLayout. Each item is constructed from a XML file (listitem_deelnemerreactie.xml) which defines the layout for a reaction item. The top level of this layout file is a LinearLayout my itself.
I want some spacing between the separate elements, as well as some right margin. The most straightforward way to so this should be: setting a bottom and right margin on the top-level LinearLAyout element of the listitem_deelnemerreactie.xml layout file.
But setting the bottom margin on the LinearLayout has no effect on the vertical spacing, though the right margin does have an effect.
The only way to be able to set a vertical margin appears to be: setting is in the Java code, after attaching the inflated view to the container.
See the two images for the effect and the code.
Though setting the margins in the code is a working workaround, I still think it is strange this cannot be achieved in the XML. Why is the bottom margin attribute ignored while the right margin is not?
Any ideas?
Have you tried to set an android:padding="10dp" for example on your elements to spaced them ?
hi I have 2 layout inside a framelayout and i want one linearlayout at top and another at bottom where i will specify height for both the layouts
and how to set this parameter for the linearLayout "layout_gravity " by code not by XML
Use a surfaceView , the SurfaceView allows you to stack in the Z order.
Docs
make sure your surfaceView is under the views of the views you want to stack.
Hope this helps
first fetch the layout from id.
LinearLayout layout = (LinearLayout)findViewById(R.id.IDOFLAYOUT);
//the set the gravity by this method
layout.setGravity(Gravity.CENTER);