gpt4 book ai didi

android - WebView 没有出现在 LinearLayout 上

转载 作者:行者123 更新时间:2023-11-29 01:39:29 25 4
gpt4 key购买 nike

我在以线性布局显示 WebView 时遇到问题。在我的代码中,我可以将 WebView View 更改为 TextView,并且一切正常。我想显示 11 个包含 Google 搜索结果的 WebView 面板。

我的MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
...
LinearLayout relLay = (LinearLayout) findViewById(R.id.main_relLay);
LayoutInflater inflater = (LayoutInflater) getApplication()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

for(int i=1; i<11; i++){
View v_child = inflater.inflate(R.layout.row, null);
relLay.addView(v_child);
String link = "https://www.google.com/search?q=" + i;

WebView web_view = (WebView) v_child.findViewById(R.id.row_webView);
web_view.loadUrl(message);
}
...

我的activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ScrollView
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="450dp" >

<LinearLayout
android:id="@+id/main_relLay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0B7A3B"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</RelativeLayout>

我的行.xml

<?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" >
<WebView
android:id="@+id/row_webView"
android:background="#323232"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="gone" >
</WebView>
</LinearLayout>

最佳答案

默认情况下,您的 WebView 可见性保持GONE,这就是它不显示的原因。

只需从 xml 文件的 WebView 中删除行 android:visibility="gone"

 <WebView
android:id="@+id/row_webView"
android:background="#323232"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
> //Remove visibility line.
</WebView>

关于android - WebView 没有出现在 LinearLayout 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25640999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com