Android layout TextView扩展布局,但webview不扩展布局
我有一个文本视图的布局,底部有一些按钮。文本视图设置为展开以填充空间。这很好。但是,当我将textview更改为webview时,webview不会展开以填充空间。怎么了 这很好:Android layout TextView扩展布局,但webview不扩展布局,android-layout,Android Layout,我有一个文本视图的布局,底部有一些按钮。文本视图设置为展开以填充空间。这很好。但是,当我将textview更改为webview时,webview不会展开以填充空间。怎么了 这很好: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<!-- height set to fill because background is black and we want
the light background -->
<TextView
style="@style/subtopicView"
android:id="@+id/subtopic_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</ScrollView>
<include layout="@layout/include_html_view_footer" />
</LinearLayout>
这不是,但唯一的更改是将textview更改为webview,并且所有其他值保持不变
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<!-- height set to fill because background is black and we want
the light background -->
<WebView
style="@style/subtopicView"
android:id="@+id/subtopic_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ScrollView>
<include layout="@layout/include_html_view_footer" />
</LinearLayout>
其中包括以下内容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/tintedColour"
android:orientation="horizontal"
android:paddingBottom="@dimen/spacer"
android:paddingTop="@dimen/spacer" >
<Button
android:id="@+id/PrevPage"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/previous" />
<Button
android:id="@+id/NextPage"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/next" />
<Button
android:id="@+id/Copy"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/copyclipboard" />
</LinearLayout>
谢谢您的帮助。通常情况下,像在ScrollView中包含WebView那样嵌套可滚动元素是个坏主意。触摸事件将是不可预测的,完全删除ScrollView可能是一个更好的主意 也就是说,Web视图的高度设置为
fill\u parent
。但是,ScrollView同时尝试最小化其子项的大小:
为了达到这个效果,我看到一些Android开发者试图在滚动视图中设置视图的高度来填充父视图。这样做不起作用,并导致以下结果:
要理解这个结果,您必须记住android:layout\u height=“fill\u parent”的意思是“将高度设置为父视图的高度”。这显然不是您在使用滚动视图时想要的。毕竟,如果ScrollView的内容总是和它本身一样高,它将变得毫无用处
通过设置android:fillViewport=“true”,滚动视图的子视图将扩展到滚动视图的高度。(当孩子比滚动视图高时,该属性无效。)谢谢,对不起,我忘了+1这个。我猜我是这样想的,因为我需要在文本视图周围使用滚动条布局,所以我必须对webview也这样做。另外,使用fillviewport意味着我可以删除关于使用fill\u parent和使用wrap\u内容的警告:)