0

Let's assume a device of 800x1280 pixels in portrait mode with the following layout:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MyScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:scrollbars="none"
    android:fadingEdgeLength="0dip" >
    <LinearLayout
        android:id="@+id/MyLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    </LinearLayout>
</ScrollView>

and with android:configChanges="orientation" in the Activity manifest.

Dynamically I add two childs views to MyLinearLayout with Layout of width = MATCH_PARENT and height = getWindowManager().getDefaultDisplay().getHeight(). So, I can scroll vertically between the two childs, each occuping a entire screen.

Now, when the device gets in landscape, the child's width get the dimension of 1280, stretching from the original 800, because of the MATCH_PARENT attribute.

Vertically, they are not stretched, since they were created with a fixed height of 1280 originally, they keep with 1280 of height.

What's the proper way to stretch this views vertically?

If I try to child.setLayoutParams inside onConfigurationChanged to width = MATCH_PARENT and height = 2048 (which is 1280 * 1280/800), I get an exception.

oblitum
  • 11,380
  • 6
  • 54
  • 120

1 Answers1

0

I'm working with dynamically instantiated CanvasView (from the S-Pen SDK) childs. I was able to do what I wanted with the help of this answer.

I have inherented com.samsung.sdraw.CanvasView and overrided onMeasure to preserve aspect ratio the way I wanted, and I needed to call setEnableZoom(false) for each child to correct content stretching, it was stretching the contents in double in landscape mode, going out of the screen boundaries.

Community
  • 1
  • 1
oblitum
  • 11,380
  • 6
  • 54
  • 120