以下 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);
例子:
TextView
应该是底部黑色空间所在的位置,但当然更高。非常感谢任何帮助,谢谢。
最佳答案
如果您尝试使 WebView
围绕 TextView
调整大小(我假设这就是您想要的,因为您拥有 android:weight
属性),确保将高度设置为“0dp
”而不是“fill_parent
”。否则,WebView
将填充父 View ,而您的 TextView
将不会显示。
此外,由于 TextView
的高度设置为“wrap_content
”,如果您想查看内容,实际上需要那里的内容。设置文本后看看它是否显示。
关于android - 以编程方式显示 WebView 下面有一个 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11281094/