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

标签 android android-layout webview textview

以下 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> should be where the back space at the bottom is, but taller of course.

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

最佳答案

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

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

关于android - 以编程方式显示 WebView 下面有一个 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11281094/

相关文章:

Android Layout设计原则

android - 约束布局 : Textview text overlap button

ios - 使用 swift 中的按钮操作控制网页 View

Android 6 WebView 运行内存不足

android - 以编程方式更改图层列表中形状的颜色

android - 连接到本地主机 :3000 refused on Android device

android - 禁用 Activity 中的电源按钮

java - 将“设置” Activity 连接到“Activity 2”后,我的应用程序崩溃了

android - 为什么我们在使用 CollapsingToolbarLayout 的时候还需要 AppBarLayout?

WebView 中的 Android +1 按钮