gpt4 book ai didi

android - ListView 与网页 View

转载 作者:太空宇宙 更新时间:2023-11-03 11:29:38 25 4
gpt4 key购买 nike

我正在尝试创建一个内部带有 Webview 的 ListView,但该应用程序没有显示任何内容。这是我的代码:

我设置 CustomAdapter 的 MainActivity

    public class Web_in_list1Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

ListView lv = (ListView)findViewById(R.id.listView2);
ListViewAdapter adapter = new ListViewAdapter(this);

lv.setAdapter(adapter);

}
}

获取自定义适配器的 View 在这里,我获取了 ListView 的布局并设置了 Webview 的 URL

    public View getView(int arg0, View convertView, ViewGroup arg2) {
// TODO Auto-generated method stub

LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(R.layout.listitem, null);

WebView wv = (WebView)convertView.findViewById(R.id.webview);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl("http://www.google.com");

convertView.setTag(wv);

return convertView;
}

主.xml

     <?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">

<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:id="@+id/listView2"
android:layout_width="fill_parent"/>
</LinearLayout>

列表项.xml

    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">


<WebView

android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

关闭!使用 SCROLLVIEW 解决的问题

最佳答案

i'm trying to create a ListView with a Webview inside

你不能可靠地将可滚动的东西放在其他可滚动的东西里面。因此,您不能可靠地:

  • ListView 行中放置一个 WebView
  • ListView 行中放置一个 ScrollView
  • WebView 放入 ScrollView
  • ListView 放入 ScrollView

此外,WebView 是一个非常重量级的小部件,其设计目的不是为了让大量副本四处 float 。请考虑使用 TextView 进行轻量级 HTML 渲染。

关于android - ListView 与网页 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8456554/

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