制作网页的Android客户端

提兵百万西湖上,立马吴山第一峰!这篇文章主要讲述制作网页的Android客户端相关的知识,希望能为你提供帮助。
3.显示内容得到了需要的属性,接下来就是展示了
【制作网页的Android客户端】MainActivity使用一个ListView显示NewsList集合的内容
NewsContentActivity通过Intent从MainActivity传递link,使用一个WebView显示新闻的详细内容。
需要注意的是webview加载URL使用的是loadDataWithBaseURL()这个方法,第一个属性是baseUrl,用来使相对地址的link属性变成绝对地址。
这个html文件头

String head="< head> < style> img{max-width:100%; width:auto; height:auto; }< /style> < style> iframe{max-width:100%; width:auto; height:auto; }< /style> < /head> ";

  可以让图片和视频播放器适应手机的大小
package com.saltwater.animenews; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.annotation.StringRes; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.webkit.WebView; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import java.io.IOException; public class NewsContentActivity extends AppCompatActivity { String baseUrl="http://www.animenewsnetwork.com/"; //String testurl="news/2016-10-30/angel-beats-heaven-door-manga-ends-new-manga-of-true-arc-starts-in-2017/.108274"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_news_content); final Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { WebView wvContent= (WebView) findViewById(R.id.wvContent); wvContent.getSettings().setjavascriptEnabled(true); wvContent.loadDataWithBaseURL(baseUrl,msg.obj.toString(),"text/html","utf-8",null); } }; /*获取新闻内容*/ newThread(new Runnable() { @Override public void run() { try { Intent intent=getIntent(); String link=intent.getStringExtra("link"); Document doc = Jsoup.connect(baseUrl+link).get(); String head="< head> < style> img{max-width:100%; width:auto; height:auto; }< /style> < style> iframe{max-width:100%; width:auto; height:auto; }< /style> < /head> "; String bodyHTML=doc.select("div[class=meat]> *").toString(); String HTML="< html> "+head+"< body> "+bodyHTML+"< /body> < /html> "; Message message=new Message(); message.obj=HTML; handler.sendMessage(message); } catch (Exception e){ e.printStackTrace(); } } }).start(); } }

listview的item布局
news_list_item.xml
< ?xml version="1.0" encoding="utf-8"?> < RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> < TextView android:id="@+id/tvTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="title" android:textSize="22dp" android:textStyle="bold" android:textColor="@color/colorPrimaryDark" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:maxLines="3" android:ellipsize="end"/> < TextView android:id="@+id/tvPubData" android:layout_width="wrap_content" android:layout_height="22dp" android:layout_below="@id/tvTitle" android:layout_alignParentLeft="true" android:text="time"/> < TextView android:id="@+id/tvCategory" android:layout_width="wrap_content" android:layout_height="22dp" android:layout_below="@id/tvTitle" android:layout_alignParentRight="true" android:text="Category"/> < LinearLayout android:layout_width="match_parent" android:layout_height="120dp" android:layout_below="@id/tvPubData" android:weightSum="1"> < TextView android:id="@+id/tvDescription" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" android:textSize="18dp" android:textColor="@color/colorBlack" android:maxLines="5" android:ellipsize="end" android:text="Description"/> < ImageView android:id="@+id/imgViewCover" android:layout_width="0dp" android:layout_height="120dp" android:layout_weight="0.5" android:src="https://www.songbingjia.com/android/@mipmap/ic_launcher"/> < /LinearLayout> < /RelativeLayout>

5.封面显示(todo)

    推荐阅读