利用ListView实现新闻客户端的新闻内容图文混排
生活随笔
收集整理的這篇文章主要介紹了
利用ListView实现新闻客户端的新闻内容图文混排
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
如圖:
布局文件:<LinearLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"
? ? xmlns:tools="<a href="http://schemas.android.com/tools">http://schemas.android.com/tools</a>"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:orientation="vertical"
? ? tools:context=".MainActivity" >
<ListView?
? ???android:layout_width="match_parent"
? ???android:layout_height="match_parent"
? ???android:id="@+id/img_txt_list"
? ???android:focusable="true"
? ???android:scrollingCache="true"
? ???android:divider="#00000000"
? ???android:scrollbars="none"
? ???/>
</LinearLayout>
<p> </p> 復制代碼
@Override
? ? ? ? public boolean isEnabled(int position) { //屏蔽listView的每個item的高亮效果
? ? ? ? ? ? ? ? return false;
? ? ? ? } 復制代碼
讀取assets下的json文件,用于模擬網絡請求:
public List<Content> getAssetsData(){
? ? ? ? ? ? ? ? AssetManager am = this.getAssets();
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? ? ? InputStream is = am.open(path);
? ? ? ? ? ? ? ? ? ? ? ? ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
? ? ? ? ? ? ? ? ? ? ? ? byte[] bt = new byte[1024];
? ? ? ? ? ? ? ? ? ? ? ? int len = 0;
? ? ? ? ? ? ? ? ? ? ? ? while((len = is.read(bt)) != -1){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? outputStream.write(bt, 0, len);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? outputStream.close();
? ? ? ? ? ? ? ? ? ? ? ? is.close();
? ? ? ? ? ? ? ? ? ? ? ? String json = outputStream.toString();
? ? ? ? ? ? ? ? ? ? ? ? list = AnalysisJSON.getProvinceCities(json);
? ? ? ? ? ? ? ? } catch (IOException e) {
? ? ? ? ? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? return list;
? ? ? ? }
復制代碼
新聞類的圖文混排目前想到的有3種類型的解決辦法:
本文是一種,另外兩種接下來會逐一介紹,另附demo供網友測試!
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
布局文件:
本文是一種,另外兩種接下來會逐一介紹,另附demo供網友測試!
img.jpg?
總結
以上是生活随笔為你收集整理的利用ListView实现新闻客户端的新闻内容图文混排的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小巫新闻客户端底部菜单切换实现
- 下一篇: ListView详解 (ListView