1.將txt文件中相似下面的文章用列表顯示出來html
title=話題|帶父母去旅行,他們的真實感覺是什麼?,url=http://www.qnwz.cn/html/221/201512/606352.html title=方式|本店只賣一本書,過時不候,url=http://www.qnwz.cn/html/221/201512/606148.html title=記事|背詩這件小事,終究是很動人的呀,url=http://www.qnwz.cn/html/221/201512/606147.html title=賞味|三百年酸辣不敗:文火慢燉的冬蔭功湯,url=http://www.qnwz.cn/html/221/201512/605855.html title=爭議|丹麥人如何在孩子面前,平靜地解剖一頭獅子,url=http://www.qnwz.cn/html/221/201512/605851.html title=人物|這對soulmate不愛花錢,2900億說捐就捐了,url=http://www.qnwz.cn/html/221/201512/605373.html title=視野|女性專屬車箱能解決性騷擾嗎?,url=http://www.qnwz.cn/html/221/201512/605371.html title=話題|乾淨不乾淨,url=http://www.qnwz.cn/html/221/201512/605370.html title=人物|科比:個人身體知道,是時候說再見了,url=http://www.qnwz.cn/html/221/201512/604860.html title=記事|魚背上沒刺的那塊肉給你,蛋糕上的那顆櫻桃也給你,url=http://www.qnwz.cn/html/221/201511/604716.html title=視野|各校面試題多「奇葩」:海盜如何分贓?保溫箱會不會思考?,url=http://www.qnwz.cn/html/221/201511/604715.html title=記事|在人間趕路,url=http://www.qnwz.cn/html/221/201511/604213.html title=文化|永不過期的「屁笑話」,url=http://www.qnwz.cn/html/221/201511/604212.html title=隨筆|讓我滾熱的靈魂在冰霜上撒個野,url=http://www.qnwz.cn/html/221/201511/604211.html title=人物|「貴族」蔡康永:回想少年時,經常殺氣很重,url=http://www.qnwz.cn/html/221/201511/604000.html title=攻略|參加校友會的正確姿式,url=http://www.qnwz.cn/html/221/201511/603999.html title=知客|跑步機的黑暗史,url=http://www.qnwz.cn/html/221/201511/603605.html title=音樂|夢見家與母親:一首美國歌的漢化之旅,url=http://www.qnwz.cn/html/221/201511/603604.html title=小說|最美的不是下雨天,是曾與你躲過雨的屋檐,url=http://www.qnwz.cn/html/221/201511/603063.html title=隨筆|高學歷的野蠻人,url=http://www.qnwz.cn/html/221/201511/602877.html代碼以下android
private void read(){ try{ InputStream in = getResources().openRawResource(R.raw.easy); int length=in.available(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); String s=""; while((s=br.readLine())!=null){ String[] sa=s.split(","); l1.add(sa[0].substring(6)); l2.add(sa[1].substring(4)); } in.close(); br.close(); }catch (Exception e){ e.printStackTrace(); } }
2.首頁佈局,很是簡單就是listviewgit
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.chen.qnwj.MainActivity"> <ListView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/list" ></ListView> </RelativeLayout>
3.每篇文章的佈局都採用的webview控件,直接實現網頁瀏覽github
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <WebView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/webview" ></WebView> </LinearLayout>
4.瀏覽頁的業務實現web
public class web extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.item); Intent in=getIntent(); Bundle bundle=in.getExtras(); int n=bundle.getInt("position"); WebView web=(WebView)findViewById(R.id.webview); WebSettings webSettings = web.getSettings(); webSettings.setSupportZoom(true); webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setBuiltInZoomControls(true);//support zoom webSettings.setUseWideViewPort(true);// 這個很關鍵 webSettings.setLoadWithOverviewMode(true); web.loadUrl(MainActivity.l2.get(n)); web.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); } }
效果圖:面試
代碼地址:ide
碼雲 https://git.oschina.net/nanxun/QNWJ佈局
github:https://github.com/nanxung/QNWJui