当我不希望活动重新启动时,如何修复OnConfigurationChanged中的布局

时间:2014-11-04 10:04:04

标签: java android android-layout

所以我修改了我的活动重新开始改变方向(我需要为客户端要求做这件事)但现在我在修复显示布局方面遇到了问题。我尝试了很多layout_height和{{1}的组合但是失败了。

我只需要一些指导如何解决这个问题。

我的布局xml:

layout_weight

我在<?xml version="1.0" encoding="UTF-8"?> <!-- /* Session screen layout Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ --> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/session_root_view" android:background="#F7FE2E" > <!-- childs are specified bottom-up so that we have a correct z-order in our final layout --> <android.inputmethodservice.KeyboardView android:id="@+id/extended_keyboard" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:visibility="gone" /> <com.freerdp.freerdpcore.presentation.ScrollView2D android:id="@+id/sessionScrollView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@id/extended_keyboard" android:scrollbars="horizontal|vertical" android:layout_alignParentTop="true" android:fillViewport="true" android:background="#FF0040" android:drawingCacheQuality="high" android:isScrollContainer="true" > <com.freerdp.freerdpcore.presentation.SessionView android:id="@+id/sessionView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:focusable="true" android:focusableInTouchMode="true" android:drawingCacheQuality="high" /> </com.freerdp.freerdpcore.presentation.ScrollView2D> <com.freerdp.freerdpcore.presentation.TouchPointerView android:id="@+id/touchPointerView" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/touch_pointer_default" android:visibility="invisible" /> <android.widget.ZoomControls android:id="@+id/zoomControls" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@id/sessionScrollView" android:layout_centerHorizontal="true" /> <android.inputmethodservice.KeyboardView android:id="@+id/extended_keyboard_header" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:visibility="gone" android:layout_centerHorizontal="true" /> </RelativeLayout> 中使用的相关代码:

onConfigurationChanged

最初在肖像中的屏幕截图:

enter image description here

在横向时的屏幕截图:

enter image description here

感谢。

2 个答案:

答案 0 :(得分:0)

您的视图可能会使用fill_parent填充屏幕。但是纵向宽高比图像不适合作为横向布局中的背景。

使用不同的横向宽度和高度图像并在drawable-land文件夹中使用(图像名称应相同)

来自drawable-land的图像将自动选择用于横向布局

答案 1 :(得分:0)

试试这个

LayoutParams p = scrollView.getLayoutParams();
LayoutParams p1 = sessionView.getLayoutParams();
DisplayMetrics outMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);

p.width = outMetrics.widthPixels;
p.height = outMetrics.heightPixels
p1.width = outMetrics.widthPixels;
p1.height = outMetrics.heightPixels