public class AlbumActivity extends BaseActivity implements View.OnClickListener {仍然使用了通用的列表布局: activity_listview
private TextView txt_title;
private ImageView img_talk;
private ListView mlistview;
private View layout_head;
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_listview);
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void initControl() {
findViewById(R.id.img_back).setVisibility(View.VISIBLE);
txt_title = (TextView) findViewById(R.id.txt_title);
txt_title.setText("朋友圈");
img_talk = (ImageView) findViewById(R.id.img_right);
img_talk.setVisibility(View.VISIBLE);
img_talk.setImageResource(R.drawable.icon_talk);
mlistview = (ListView) findViewById(R.id.listview);
layout_head = getLayoutInflater().inflate(R.layout.layout_album_header, null);
mlistview.addHeaderView(layout_head);
mlistview.setAdapter(new AlbumAdpter(this));
}
@Override
protected void initView() {
// TODO Auto-generated method stub
}
@Override
protected void setListener() {
findViewById(R.id.img_back).setOnClickListener(this);
img_talk.setOnClickListener(this);
img_talk.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Utils.showLongToast(context, "长按发送文字");
return true;
}
});
}
@Override
protected void initData() {
// TODO Auto-generated method stub
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.img_back:
Utils.finish(AlbumActivity.this);
break;
case R.id.img_right:
Utils.start_Activity(this, ShareActivity.class);
break;
default:
break;
}
}
}
增加了一个列表头:
layout_album_header
<?xml version="1.0" encoding="utf-8"?>适配器是 AlbumAdpter:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:background="@color/white"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="280dp">
<TextView
android:textSize="20sp"
android:id="@+id/txt_name"
android:text="菲儿"
android:gravity="right|bottom"
android:paddingRight="110dp"
android:paddingBottom="10dp"
android:background="@drawable/user_ba"
android:layout_width="fill_parent"
android:textColor="@color/white"
android:layout_height="240dp" />
<ImageView
android:id="@+id/head"
android:contentDescription="@string/app_name"
android:layout_width="80.0dip"
android:layout_height="80.0dip"
android:layout_marginRight="15dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:src="@drawable/head" />
</RelativeLayout>
</LinearLayout>
public class AlbumAdpter extends BaseAdapter {
protected Context context;
LayoutInflater mInflater;
public AlbumAdpter(Context ctx) {
context = ctx;
}
@Override
public int getCount() {
return 15;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.layout_item_album, parent, false);
}
return convertView;
}
}
子项布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/contactitem_layout"
style="@style/MMListItem"
android:gravity="top"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="10dip" >
<ImageView
android:id="@+id/img_head"
android:layout_width="50.0dip"
android:layout_height="50.0dip"
android:scaleType="centerCrop"
android:src="@drawable/head" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="vertical"
android:paddingLeft="10dip"
android:paddingBottom="5dp">
<TextView
android:id="@+id/txt_content"
style="@style/MMFontTitleInList"
android:textColor="@color/blue1"
android:textSize="18sp"
android:text="老婆" />
<TextView
android:id="@+id/txt_msg"
android:layout_below="@+id/txt_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是多幸福啊!辛苦了亲爱的!么么哒!~"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textSize="16sp"
android:singleLine="true" />
<LinearLayout
android:id="@+id/layout_photo"
android:layout_below="@+id/txt_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center_vertical">
<ImageView
android:id="@+id/img_photo1"
android:layout_width="80.0dip"
android:layout_height="80.0dip"
android:scaleType="centerCrop"
android:src="@drawable/gr" />
<ImageView
android:id="@+id/img_photo2"
android:layout_margin="5dp"
android:paddingLeft="10dp"
android:layout_width="80.0dip"
android:layout_height="80.0dip"
android:scaleType="centerCrop"
android:src="@drawable/gr" />
<ImageView
android:id="@+id/img_photo3"
android:layout_margin="5dp"
android:paddingLeft="10dp"
android:layout_width="80.0dip"
android:layout_height="80.0dip"
android:scaleType="centerCrop"
android:src="@drawable/gr" />
</LinearLayout>
<TextView
android:id="@+id/txt_time"
android:layout_below="@+id/layout_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="56分钟前"
android:textColor="@color/black1"
android:textSize="12sp"
android:singleLine="true" />
<ImageView
android:id="@+id/img_zan"
android:layout_alignParentRight="true"
android:layout_below="@+id/layout_photo"
android:layout_width="23dp"
android:layout_height="16dp"
android:scaleType="fitXY"
android:src="@drawable/afr" />
</RelativeLayout>
</LinearLayout>
<View
android:background="@color/black2"
android:layout_width="fill_parent"
android:layout_height="1.0dip" />
</LinearLayout>