【问题标题】:WebView size is expanding but not contracting as per the text in itWebView 的大小正在扩大,但没有按照其中的文本收缩
【发布时间】:2012-06-01 06:52:59
【问题描述】:

我正在使用 WebView 来显示解析的 XML 和 HTML 内容。我已将 webview 的 layout_height 设置为 wrap_content。当物质很大时它工作得很好,但是当物质很小时它不会包裹到它下面的空间仍然是白色的。请告诉我每次更改 webView 中的内容时如何包装它。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background = "#ffffff"
>

<LinearLayout  android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background = "#ffffff" >

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

<LinearLayout android:layout_width = "fill_parent"
 android:layout_height = "wrap_content"
 android:orientation = "horizontal"
 android:id = "@+id/buttons"
 android:background="#ffffff">
 <Button android:layout_height = "wrap_content"
     android:layout_width = "0dp" 
     android:id = "@+id/previousdata"         
     android:text = "Back"
     android:layout_weight = "1"
      android:layout_gravity="center_vertical"/>
   <Button android:layout_height = "wrap_content"
     android:layout_width = "0dp" 
     android:id = "@+id/nextdata"
     android:layout_weight = "1"
     android:text = "Next"
     android:layout_gravity="center_vertical"/>
  </LinearLayout>
</LinearLayout> 
 </ScrollView>

现在我遇到的问题是,如果我在纵向模式下运行我的应用程序,webView 会提供额外的空白空间而不是根据数据收缩,但是如果我将方向更改为横向,空白空间会减少......请解释一下我的观点发生了什么,我怎样才能减少额外的空白......提前谢谢......

【问题讨论】:

  • 这个链接也和下面一样,没有确切的解决方案...请找出一些正确的解决方案..thanx提前.. :)
  • 你能发布你的布局 XML 吗?
  • @Anthony Atkinson:我已经发布了我的 xml,请告诉我解决方案。提前谢谢.. :)
  • 现在我会遇到问题,如果我将视图从纵向更改为横向,它的设置是否正确......但每次我必须这样做......当内容发生变化时。

标签: android webview


【解决方案1】:

Android 属性: 布局中的android:layout_weight = "1 应该可以工作...

【讨论】:

  • 不,先生...当您在此处提及时,我已再次尝试,但没有...请提供一些解决方案...提前谢谢..
  • 它有效,但只有当我们有一个线性布局作为父级时,如果我们将该线性布局作为滚动视图的子级,它就不起作用..
  • 你用过android:layout_height="0dp" 吗?
  • 不,没关系,当我使用这种方法时,视图完全消失了,但现在我在线性布局中单独使用了 webview,并消除了滚动视图父级,它对我来说工作正常。但是,如果您可以检查它为什么它不能在滚动视图中工作,那么请告诉..
  • 嗨,在线性布局中添加你的 webview,然后尝试使用 android:layout_weight = "1"
猜你喜欢
  • 1970-01-01
  • 2011-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-14
  • 1970-01-01
  • 1970-01-01
  • 2014-05-25
相关资源
最近更新 更多