【问题标题】:Add Webview at the end of ListView in Android在Android中ListView末尾添加Webview
【发布时间】:2015-08-27 07:58:20
【问题描述】:

我正在尝试在片段布局的列表视图末尾添加 webview。

这是我的片段布局。

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


    <TextView
        android:id="@+id/txtTheQueue"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/txt_the_queue"
        android:textStyle="bold" />

    <ListView
        android:id="@+id/list_queue"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtTheQueue" />

    <WebView
        android:id="@+id/webViewQueue"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/list_queue" />    
</RelativeLayout>

我尝试将 webview 添加到 listview 的页脚。 但得到这个例外:

java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

帮帮我。

【问题讨论】:

  • 请发布您的代码
  • @IntelliJ Amiya:我已经提到我正在遇到 ClassCastException ..

标签: android listview android-fragments android-listview webview


【解决方案1】:

解决了。

只需将您的 webview 添加到相对布局,然后将此布局添加到列表视图的页脚。 我收到此错误是因为 listview 和 scrollview 的布局参数不同,并且不在 a​​ndroid 中的同一棵树中。

代码如下:

 WebView lWebView = new WebView(getActivity());
 lWebView.loadUrl("file:///android_asset/queue.html");
 RelativeLayout relativeLayout = new RelativeLayout(getActivity());
 relativeLayout.addView(lWebView);
 listQueue.addFooterView(relativeLayout);

【讨论】:

  • 从错误中可以明显看出你必须使用相对布局,你已经自己弄清楚了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多