假設在縱向模式下的800x1280像素裝置具有以下佈局:如何在旋轉ScrollView時保持元素的高寬比?
<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>
與機器人:configChanges =「方向」在活動清單。
動態我添加兩個兒童的觀點與寬度= MATCH_PARENT和高度= getWindowManager()。getDefaultDisplay()的佈局來MyLinearLayout。的getHeight()。所以,我可以在兩個孩子之間垂直滾動,每個孩子都佔據整個屏幕。
現在,當設備進入橫向時,由於MATCH_PARENT屬性,孩子的寬度得到1280的維度,從原始800延伸。
垂直方向上,它們沒有拉伸,因爲它們最初創建時的固定高度爲1280,它們保持高度爲1280。
什麼是垂直拉伸視圖的正確方法?
如果我嘗試將onConfigurationChanged中的child.setLayoutParams設置爲width = MATCH_PARENT和height = 2048(即1280 * 1280/800),則會出現異常。