Programmatically set layout_gravity for FrameLayout Child?

This seems to be trivial, but I can't figure out how to programmatically set layout_gravity for a FrameLayout descendant for life.

There were a lot of similar questions on SO, but after trying more than 10 of them, none of the solutions to setGravity, the new FrameLayout.LayoutParams, etc., seems to work.

Below is a simplified version of what I'm trying to achieve.

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextureView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"/>
</FrameLayout>

However, for external reasons, I am adding TextureView to FrameLayout programmatically.

mCameraPreview = new CameraPreview(this, recordMode);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview_wrapper);
preview.addView(mCameraPreview);

When I try to set layout_gravity to mCameraPreview, it only gives me the possibility of gravity, which I don't need.

Is there something I'm missing here?

+4
source share
1 answer

layout_gravity FrameLayout.LayoutParams, . - :

mCameraPreview = new CameraPreview(this, recordMode);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview_wrapper);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
    FrameLayout.LayoutParams.MATCH_PARENT, 
    FrameLayout.LayoutParams.MATCH_PARENT, 
    Gravity.BOTTOM);
preview.addView(mCameraPreview, params);
+6

Source: https://habr.com/ru/post/1599153/


All Articles