代码:http://download.youkuaiyun.com/detail/huangbin95487710/9260165
依赖包模式
完整运行还需要用到以下依赖包
- 布局
<?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:pla="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" > <General.View.Pla.PlaXListView android:id="@id/pla_xlistview" style="@style/MyDivPlaXListView" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFffffff" android:fastScrollEnabled="true" android:scrollbars="vertical" pla:pla_ColumnNumber="2" pla:pla_LandscapeColumnNumber="3" /> </merge>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@id/pla_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/view_pla_frame" android:orientation="vertical" > <General.View.ImageViewLayout android:id="@id/pla_pic" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@null" /> <TextView android:id="@id/pla_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="false" android:textColor="#656565" /> <TextView android:id="@id/pla_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|bottom" android:gravity="right" android:textColor="#9f9f9f" /> </LinearLayout>
- 样式
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="MyDivPlaXListView" parent="@style/DivXListView"> <item name="xlv_footer_bg">#FFffffff</item> <item name="xlv_footer_font_size">16sp</item> <item name="xlv_footer_font_color">#FF6e6e6e</item> <item name="xlv_header_bg">#FFffffff</item> <item name="xlv_header_font_size">16sp</item> <item name="xlv_header_font_color">#FF6e6e6e</item> <item name="xlv_page_num">10</item> <item name="xlv_touch">false</item> <item name="xlv_load">true</item> <item name="xlv_refresh">true</item> <item name="pla_ColumnNumber">2</item> <item name="pla_LandscapeColumnNumber">3</item> <item name="pla_ColumnPaddingLeft">0dip</item> <item name="pla_ColumnPaddingRight">0dip</item> </style> </resources>
- 代码
- PlaActivity.java
package cn.whonow.whonow.pla; import java.util.ArrayList; import General.Listener.XListViewListener; import General.View.Pla.PlaXListView; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import cn.whonow.whonow.R; /** * 实现XListViewListener接口 * 下拉刷新,上拉加载更多 * */ public class PlaActivity extends FragmentActivity implements XListViewListener { private PlaXListView mAdapterView = null; private PlaAdapter mAdapter = null; private ArrayList<PlaBase> mInfos = new ArrayList<PlaBase>(); @SuppressWarnings("unchecked") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test_pla); int mIndex = 0; PlaBase mDuitangInfo = new PlaBase(); mDuitangInfo.mId = (mIndex + ""); mDuitangInfo.mMsg = "我是最新的测试实际例子"; mDuitangInfo.mImgUrl = ("http://img0.bdstatic.com/img/image/shouye/gxxhxh2-9407628543.jpg"); mInfos.add(mDuitangInfo); mIndex++; mDuitangInfo = new PlaBase(); mDuitangInfo.mId = (mIndex + ""); mDuitangInfo.mMsg = "我是最新的测试实际例子"; mDuitangInfo.mImgUrl = ("http://g.hiphotos.baidu.com/image/w%3D310/sign=9abcc32ed01b0ef46ce89e5fedc551a1/b219ebc4b74543a9bc5871cc1c178a82b901146a.jpg"); mInfos.add(mDuitangInfo); mIndex++; mDuitangInfo = new PlaBase(); mDuitangInfo.mId = (mIndex + ""); mDuitangInfo.mMsg = "我是最新的测试实际例子"; mDuitangInfo.mImgUrl = ("http://c.hiphotos.baidu.com/image/w%3D310/sign=3ed7e3ef8fb1cb133e693a12ed5556da/738b4710b912c8fcc9b17ecdfe039245d688216b.jpg"); mInfos.add(mDuitangInfo); mIndex++; mDuitangInfo = new PlaBase(); mDuitangInfo.mId = (mIndex + ""); mDuitangInfo.mMsg = "我是最新的测试实际例子"; mDuitangInfo.mImgUrl = ("http://g.hiphotos.baidu.com/image/w%3D310/sign=9366b74b00087bf47dec51e8c2d2575e/8644ebf81a4c510f570a6a1a6259252dd52aa5e0.jpg"); mInfos.add(mDuitangInfo); mIndex++; mDuitangInfo = new PlaBase(); mDuitangInfo.mId = (mIndex + ""); mDuitangInfo.mMsg = "我是最新的测试实际例子"; mDuitangInfo.mImgUrl = ("http://c.hiphotos.baidu.com/image/w%3D310/sign=23853ae6257f9e2f70351b092f30e962/9922720e0cf3d7caf9c5b776f01fbe096b63a9fb.jpg"); mInfos.add(mDuitangInfo); mIndex++; mAdapterView = (PlaXListView) findViewById(R.id.pla_xlistview); mAdapterView.setPullLoadEnable(true); mAdapterView.setXListViewListener(this); mAdapter = new PlaAdapter(this); mAdapter.setValue(mInfos); mAdapterView.setAdapter(mAdapter); } @Override protected void onResume() { super.onResume(); } @Override protected void onDestroy() { super.onDestroy(); } @Override public void onRefresh() { } @Override public void onLoadMore() { } @Override public String getRequestName() { // TODO Auto-generated method stub return PlaActivity.class.getSimpleName(); } }// end of class
- PlaAdapter.java
package cn.whonow.whonow.pla; import java.util.ArrayList; import General.Inter.AsyncImageLoader; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import cn.whonow.whonow.R; public class PlaAdapter extends BaseAdapter { private Context mContext; private ArrayList<PlaBase> mInfos = new ArrayList<PlaBase>(); private AsyncImageLoader asyncImageLoader = null; public PlaAdapter(Context context) { mContext = context; asyncImageLoader = new AsyncImageLoader(mContext, R.drawable.view_no_photo); } public void setValue(ArrayList<PlaBase> mInfos) { this.mInfos = mInfos; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { LayoutInflater layoutInflator = LayoutInflater.from(parent .getContext()); convertView = layoutInflator.inflate(R.layout.test_pla_item, null); holder = new ViewHolder(); holder.imageView = (ImageView) convertView .findViewById(R.id.pla_pic); holder.contentView = (TextView) convertView .findViewById(R.id.pla_title); convertView.setTag(holder); } holder = (ViewHolder) convertView.getTag(); PlaBase duitangInfo = mInfos.get(position); holder.contentView.setText(duitangInfo.mMsg); asyncImageLoader.load(duitangInfo.mImgUrl, holder.imageView); return convertView; } class ViewHolder { ImageView imageView; TextView contentView; TextView timeView; } @Override public int getCount() { return mInfos.size(); } @Override public Object getItem(int arg0) { return mInfos.get(arg0); } @Override public long getItemId(int arg0) { return 0; } }
- PlaBase.java
package cn.whonow.whonow.pla; public class PlaBase { public String mId = ""; public String mMsg = "";// 信息 public String mImgUrl = "";// 地址 }
- 效果图