让我们假设设备在纵向模式下为800x1280像素,布局如下:
<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>以及在活动清单中使用android:configChanges="orientation"。
动态地,我在MyLinearLayout中添加了两个子程序视图,其布局为宽度= MATCH_PARENT和height =所以,我可以在两个孩子之间垂直滚动,每个孩子都会出现一个完整的屏幕。
现在,当设备进入景致时,由于MATCH_PARENT属性,子设备的宽度从原来的800扩展到1280。
垂直上,它们不被拉伸,因为它们最初是以1280的固定高度创建的,所以它们保持着1280的高度。
垂直拉伸这个视图的正确方法是什么?
如果我尝试在child.setLayoutParams内部onConfigurationChanged到width = MATCH_PARENT和which= 2048 (即1280 * 1280/800),我就会得到一个异常。
发布于 2012-06-07 20:07:48
我正在使用动态实例化的CanvasView (来自SDK) childs。在this answer的帮助下,我能够做我想做的事情。
我继承了com.samsung.sdraw.CanvasView,并重写了onMeasure,以保持我想要的方式的纵横比,我需要为每个孩子调用setEnableZoom(false)来纠正内容拉伸,它是在景观模式下以双倍方式拉伸内容,超出屏幕边界。
https://stackoverflow.com/questions/10924074
复制相似问题