How to correctly position a piece of the View created in java?

Asked

Viewed 96 times

2

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


inserir a descrição da imagem aqui


The top layer of this menu is a FrameLayout, I’d like to leave you with Gravity RIGHT and BOTTOM, but I don’t know how to pass these characteristics by

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 set it up in this way:

<FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"/>
  • That, let it bottom | Right, that’s my question, the rest I’ll arrange later

  • 1

    Its linear_data is a Linearlayout?

  • It’s a frame, had written wrong

  • 1

    Good, it worked here!

1 answer

3


This definition of FrameLayout in XML, example:

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

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.