以编程方式显示一个 WebView,下面有一个 TextView

And*_*bon 1 android textview webview android-layout

以下 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>
Run Code Online (Sandbox Code Playgroud)

但是,下面的 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);
Run Code Online (Sandbox Code Playgroud)

例子:

<code>TextView</code> 应该是底部的退格所在的位置,但当然更高。

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

Mak*_*rio 5

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

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