模擬新浪微博隨便看看介面布局

2021-07-02 05:39:53 字數 1854 閱讀 8377

布局:布局中標題欄的樣式是新建的乙個xml檔案

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

"android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:background="#d2691e" >

在主布局中引用這個標題欄

主布局是乙個listview控制項

listview控制項中還需要乙個顯示資料的小布局,我是又建立了乙個xml檔案,在這個布局中我使用了布局巢狀。

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

"android:id="@+id/linearlayout2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal" > 

介面是有兩個xml檔案組成:第乙個是listview元件,另乙個是顯示的布局

布局完成之後就是資料和利用adapter使資料和布局鏈結起來。

資料是利用list集合,建立了乙個boke類和建立了乙個boke方法新增資料到集合中

public class boke

public string getname()

public void setname(string name)

public int getid()

public void setid(int id)

public string getcontent()

public void setcontent(string content)

public string gettime()

public void settime(string time)

private void boke()

最後是利用adapter把資料和布局連線在一起,建立了乙個繼承於arrayadapter的adapterboke類,並建立了adapterboke方法和getview方法把資料與布局連線到一起

主類中:

adapterboke adapter=new adapterboke(this,r.id.listview,bokelist);向adapterboke

adapterboke類中:

public adapterboke(context context,int textviewresourceid,listbokelist)

public view getview(int position, view convertview, viewgroup parent) else

viewholder.imageboke.setimageresource(boke.getid());

viewholder.name.settext(boke.getname());

viewholder.content.settext(boke.getcontent());

viewholder.createtime.settext(boke.gettime());

return convertview;

}class viewholder

viewholder的作用是快取機制,避免每次滑動螢幕都需要獲取控制項id.

最後通過 listview.setadapter(adapter);執行

模擬新浪微博 隨便看看

我們在使用android應用的時候,看到的listview效果經常也會看到和文字共存的情況。比如新狼微博中別人發布的訊息 有3個textview。用於顯示列表每一行的文字和 linearlayout xmlns android android layout width match parent an...

模擬新浪微博隨便看看欄目

使用listview來模仿微博隨便看看欄 分析 要完成這個效果,我們需要 1.listview及list itrm extends activity的編寫 2.定義資料集合 3.建立 adapter繫結資料 4.新增單擊事件 編碼 mainactivity package com.example.a...

模擬新浪微博

1.專案效果圖 主要 如下 android layout width match parent android layout height match parent android padding 10dip android orientation vertical 2 獲取xml資源 在andro...