How to properly position a piece of View created in Java?

2

After loading my View , if the user clicks the button then a menu appears on the front as shown in the image:

ThetopmostlayerofthismenuisFrameLayout,IwouldliketoleaveitwithGravityRIGHTandBOTTOM,butIdonotknowhowtopassthesefeaturesto

I'm doing it this way:

FrameLayout.LayoutParams lparams = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT,
            Gravity.RIGHT);
    frame_dados.setLayoutParams(lparams);

I want to configure it in this way:

<FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"/>
    
asked by anonymous 17.03.2017 / 15:41

1 answer

3

This setting of FrameLayout in XML, example:

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"/>

It is equivalent to this programmatically:

FrameLayout.LayoutParams lparams = new FrameLayout.LayoutParams(
    FrameLayout.LayoutParams.WRAP_CONTENT,
    FrameLayout.LayoutParams.WRAP_CONTENT);
lparams.gravity = Gravity.RIGHT | Gravity.BOTTOM;

See more details in the documentation .

    
17.03.2017 / 16:13