2010-02-26 21 views
0

我有一个webview和一个包含4个按钮的表。我已将webview的高度设置为400px,以便按钮以纵向模式显示在屏幕的底部。我的问题是,当更改为横向模式时,按钮不可见。所以当我改变方向时,我需要在运行时改变webview的高度。有谁知道如何做到这一点?我可以使用'onConfigurationChanged'函数捕获方向更改。如何更改运行时的webview的高度?


感谢CommonsWare,我给了XML如下。应用程序在启动时崩溃。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

<RelativeLayout android:layout_alignParentTop="true"> 

<WebView 
    android:id="@+id/appView" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" /> 

</RelativeLayout> 
<RelativeLayout 
    android:layout_alignParentBottom="true"> 

<TableLayout 
    android:id="@+id/TableLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical"> 

<TableRow 
    android:id="@+id/TableRow01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center"> 

<ImageButton 
    android:id="@+id/more" 
    android:padding="1dip" 
    android:src="@drawable/more1" 
    android:layout_marginRight="15dip"> 
</ImageButton> 
<ImageButton 
    android:id="@+id/albums" 
    android:padding="1dip" 
    android:src="@drawable/albums1" 
    android:layout_marginRight="15dip"> 
</ImageButton> 
<ImageButton 
    android:id="@+id/videos" 
    android:padding="1dip" 
    android:src="@drawable/videos" 
    android:layout_marginRight="15dip"> 
</ImageButton> 
<ImageButton 
    android:id="@+id/artists" 
    android:padding="1dip" 
    android:src="@drawable/artists1" 
    android:layout_marginRight="15dip"> 
</ImageButton> 
</TableRow> 
</TableLayout> 
</RelativeLayout> 
</LinearLayout> 

回答

4

设计您的布局以避免400px的硬线值。这不仅不适用于您正在测试的任何仿真器/设备的横向模式,它不会像您期望的那样在较小或较大的屏幕上工作。

请使用RelativeLayout,与像android:layout_alignParentBottom的按钮和android:layout_alignParentTopandroid:layout_aboveWebView属性。然后,您的布局将动态适应可用空间。