2015-08-27 80 views
-1

我想在我的片段布局的列表视图的末尾添加webview。在Android的ListView的末尾添加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 

帮助我。

+0

请发表您的代码 –

+0

@IntelliJ阿米亚·:我已经说过,我amgetting ClassCastException异常.. – AndiGeeky

回答

0

已解决。

只需添加您的WebView到相对布局和该布局添加到列表视图中的脚注。 我得到这个错误,因为listview和scrollview的layout-params是不同的,而不是在android中的同一棵树。

这里是代码:

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

其显而易见的错误,你必须使用相对布局,你有算起来你自己。 – Pankaj