繁体   English   中英

如何在运行时更改Web视图的高度?

[英]How to change the height of a webview on Runtime?

我有一个webview和一个包含4个按钮的表。 我已将webview的高度设置为400px,以便按钮以纵向模式显示在屏幕底部。 我的问题是,当更改为横向模式时,按钮不可见。 因此,当方向改变时,我需要在运行时更改Webview的高度。 有人知道如何实现这一目标吗? 我可以使用“ onConfigurationChanged”功能捕获方向变化。


感谢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>

设计布局时,避免使用400px值。 这不仅不能在横向模式下在您要测试的任何仿真器/设备上工作,而且也无法以您期望的方式在较小或较大的屏幕上工作。

请使用RelativeLayout ,其属性如android:layout_alignParentBottom用于按钮,而android:layout_alignParentTopandroid:layout_above用于WebView 然后,您的布局将动态适应可用空间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM