1

以下 XML 实现似乎工作正常:

<?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="fill_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/chatView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" />

    <EditText
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </EditText>
</LinearLayout>

但是,下面的 Java 实现没有(在 之后的底部有一个很小的空间WebView,但TextView是不可见的。)

Context mContext = getActivity();

LinearLayout view = new LinearLayout(mContext);
view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
view.setOrientation(LinearLayout.VERTICAL);

WebView web (new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1f));
web.loadUrl("http://www.google.com");

TextView text = new TextView(mContext);
text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

view.addView(web);
view.addView(text);

例子:

<code>TextView</code> 应该是底部的后退空间,但当然更高。

TextView应该是底部黑色空间的位置,但当然更高。任何帮助将不胜感激,谢谢。

4

2 回答 2

5

如果您尝试WebView调整周围的大小TextView(我假设这是您想要的,因为您拥有该android:weight属性),请确保将高度设置为“ 0dp”而不是“ fill_parent”。否则,WebView将填写父项,您TextView将不会显示。

此外,由于TextView' 的高度设置为“ ” wrap_content,如果你想看到它,你实际上需要那里的内容。设置文本后查看它是否显示。

于 2012-07-01T10:10:22.467 回答
0

我认为你必须在 TextView“文本”上设置一些文本

类似这样text.setText("This is text ")

于 2012-07-02T13:07:37.927 回答