Search code examples
androidandroid-webviewandroid-4.0-ice-cream-sandwichandroid-scrollview

Best way to create a header and footer for webview in Android


I want to create news like activity that has title and date and some share and favorite buttons in the beginning at the top, the article text (and maybe some images and headers titles) is in html that I get from server, and at the end a list of related news!

I have to use WebView for the article html, but since I need the header and the main webview to scroll together, I may have to use them in the in wraping ScrollView, which, apparently is not the best option!

I have red these: webview in scrollview and Disable scrolling in webview

but I want to know what is the best way to implement this as of 2015! that can work with android 4.01+


Solution

  • Well, as it turns out, best way to do yet is to just put them in a scrollView !

    It worked on my Samsung android 4.4, but I don't know about the rest !

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <RelativeLayout
            android:id="@+id/news_activity_title_lay"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
           //Some Widgets Here for header
    
        </RelativeLayout>
    
        <WebView
            android:layout_below="@+id/news_activity_title_lay"
            android:id="@+id/news_activity_web_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white">
    
        </WebView>
    
        <LinearLayout
            android:id="@+id/news_activity_related_base_lay"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_below="@+id/news_activity_web_view">
    
          //Some Widgets Here foe footer
    
        </LinearLayout>
    
    </RelativeLayout>
    

    funny thing, though is Android Studio is saying I should not do this ! :/