Android GridView 分页加载数据

来源:互联网 发布:华彩软件下载 编辑:程序博客网 时间:2024/04/30 15:17
android UI 往右滑动,滑动到最后一页就自动加载数据并显示
如图:



Java代码  收藏代码
  1. package cn.anycall.ju;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.HashMap;  
  5. import java.util.List;  
  6. import java.util.Map;  
  7.   
  8. import android.app.Activity;  
  9. import android.content.ActivityNotFoundException;  
  10. import android.content.Context;  
  11. import android.content.Intent;  
  12. import android.content.pm.ResolveInfo;  
  13. import android.os.Bundle;  
  14. import android.os.Handler;  
  15. import android.os.Looper;  
  16. import android.os.Message;  
  17. import android.view.KeyEvent;  
  18. import android.view.View;  
  19. import android.view.Window;  
  20. import android.widget.AdapterView;  
  21. import android.widget.AdapterView.OnItemClickListener;  
  22. import android.widget.GridView;  
  23. import android.widget.Toast;  
  24. import cn.anycall.ju.ScrollLayout.OnScreenChangeListenerDataLoad;  
  25.   
  26. /** 
  27.  * GridView分页显示安装的应用程序 
  28.  */  
  29. public class AllAppList extends Activity {  
  30.     private ScrollLayout mScrollLayout;  
  31.     private static final float APP_PAGE_SIZE = 4.0f;  
  32.     private Context mContext;  
  33.     private PageControlView pageControl;  
  34.     public MyHandler myHandler;  
  35.     public int n=0;  
  36.     private DataLoading dataLoad;  
  37.     @Override  
  38.     protected void onCreate(Bundle savedInstanceState) {  
  39.         // TODO Auto-generated method stub  
  40.           
  41.         super.onCreate(savedInstanceState);  
  42.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
  43.         mContext = this;  
  44.         setContentView(R.layout.main);  
  45.         dataLoad = new DataLoading();  
  46.         mScrollLayout = (ScrollLayout)findViewById(R.id.ScrollLayoutTest);  
  47.         myHandler = new MyHandler(this,1);  
  48.           
  49.         //起一个线程更新数据  
  50.         MyThread m = new MyThread();  
  51.         new Thread(m).start();  
  52.     }   
  53.       
  54.     /** 
  55.      * gridView 的onItemLick响应事件 
  56.      */  
  57.     public OnItemClickListener listener = new OnItemClickListener() {  
  58.   
  59.         public void onItemClick(AdapterView<?> parent, View view, int position,  
  60.                 long id) {  
  61.             // TODO Auto-generated method stub  
  62.             System.out.println("position="+position);  
  63.         }  
  64.           
  65.     };  
  66.       
  67.     @Override  
  68.     protected void onDestroy() {  
  69.         // TODO Auto-generated method stub  
  70.         android.os.Process.killProcess(android.os.Process.myPid());  
  71.         super.onDestroy();  
  72.     }  
  73.   
  74.     @Override  
  75.     public boolean onKeyDown(int keyCode, KeyEvent event) {  
  76.         // TODO Auto-generated method stub  
  77.         if (keyCode == KeyEvent.KEYCODE_BACK) {  
  78.             finish();  
  79.             return true;  
  80.         }  
  81.         return super.onKeyDown(keyCode, event);  
  82.     }  
  83.       
  84.       
  85.       
  86.     // 更新后台数据  
  87.     class MyThread implements Runnable {  
  88.         public void run() {  
  89.             try {  
  90.                 Thread.sleep(1000*3);  
  91.             } catch (InterruptedException e) {  
  92.                 // TODO Auto-generated catch block  
  93.                 e.printStackTrace();  
  94.             }  
  95.             String msglist = "1";  
  96.             Message msg = new Message();  
  97.             Bundle b = new Bundle();// 存放数据  
  98.             b.putString("rmsg", msglist);  
  99.             msg.setData(b);  
  100.             AllAppList.this.myHandler.sendMessage(msg); // 向Handler发送消息,更新UI  
  101.   
  102.         }  
  103.     }  
  104.   
  105.     class MyHandler extends Handler {  
  106.         private AllAppList mContext;  
  107.         public MyHandler(Context conn,int a) {  
  108.             mContext = (AllAppList)conn;  
  109.         }  
  110.   
  111.         public MyHandler(Looper L) {  
  112.             super(L);  
  113.         }  
  114.   
  115.         // 子类必须重写此方法,接受数据  
  116.         @Override  
  117.         public void handleMessage(Message msg) {  
  118.             // TODO Auto-generated method stub  
  119.             super.handleMessage(msg);  
  120.             Bundle b = msg.getData();  
  121.             String rmsg = b.getString("rmsg");  
  122.             if ("1".equals(rmsg)) {  
  123.                 // do nothing  
  124.                  List<Map> list = new ArrayList<Map>();  
  125.                  for(int i =0;i<16;i++){  
  126.                      n++;  
  127.                      Map map = new HashMap();  
  128.                         map.put("name", n);  
  129.                         list.add(map);  
  130.                  }  
  131.                       
  132.                 int pageNo = (int)Math.ceil( list.size()/APP_PAGE_SIZE);  
  133.                 for (int i = 0; i < pageNo; i++) {  
  134.                     GridView appPage = new GridView(mContext);  
  135.                     // get the "i" page data  
  136.                     appPage.setAdapter(new AppAdapter(mContext, list, i));  
  137.                     appPage.setNumColumns(2);  
  138.                     appPage.setOnItemClickListener(listener);  
  139.                     mScrollLayout.addView(appPage);  
  140.                 }  
  141.                 //加载分页  
  142.                 pageControl = (PageControlView) findViewById(R.id.pageControl);  
  143.                 pageControl.bindScrollViewGroup(mScrollLayout);  
  144.                 //加载分页数据  
  145.                 dataLoad.bindScrollViewGroup(mScrollLayout);  
  146.                       
  147.                 }  
  148.             }  
  149.   
  150.         }  
  151.       
  152.       
  153.     //分页数据  
  154.     class DataLoading {  
  155.         private int count;  
  156.         public void bindScrollViewGroup(ScrollLayout scrollViewGroup) {  
  157.             this.count=scrollViewGroup.getChildCount();  
  158.             scrollViewGroup.setOnScreenChangeListenerDataLoad(new OnScreenChangeListenerDataLoad() {  
  159.                 public void onScreenChange(int currentIndex) {  
  160.                     // TODO Auto-generated method stub  
  161.                     generatePageControl(currentIndex);  
  162.                 }  
  163.             });  
  164.         }  
  165.           
  166.         private void generatePageControl(int currentIndex){  
  167.             //如果到最后一页,就加载16条记录  
  168.             if(count==currentIndex+1){  
  169.                 MyThread m = new MyThread();  
  170.                 new Thread(m).start();  
  171.             }  
  172.         }  
  173.     }  
  174. }  


Java代码  收藏代码
  1. package cn.anycall.ju;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5. import java.util.Map;  
  6.   
  7. import android.content.Context;  
  8. import android.content.pm.PackageManager;  
  9. import android.content.pm.ResolveInfo;  
  10. import android.view.LayoutInflater;  
  11. import android.view.View;  
  12. import android.view.ViewGroup;  
  13. import android.widget.BaseAdapter;  
  14. import android.widget.ImageView;  
  15. import android.widget.TextView;  
  16.   
  17. import cn.anycall.ju.R;  
  18.   
  19. public class AppAdapter extends BaseAdapter {  
  20.     private List<Map> mList;  
  21.     private Context mContext;  
  22.     public static final int APP_PAGE_SIZE = 4;  
  23.     private PackageManager pm;  
  24.       
  25.     public AppAdapter(Context context, List<Map> list, int page) {  
  26.         mContext = context;  
  27.         pm = context.getPackageManager();  
  28.           
  29.         mList = new ArrayList<Map>();  
  30.         int i = page * APP_PAGE_SIZE;  
  31.         int iEnd = i+APP_PAGE_SIZE;  
  32.         while ((i<list.size()) && (i<iEnd)) {  
  33.             mList.add(list.get(i));  
  34.             i++;  
  35.         }  
  36.     }  
  37.     public int getCount() {  
  38.         // TODO Auto-generated method stub  
  39.         return mList.size();  
  40.     }  
  41.   
  42.     public Object getItem(int position) {  
  43.         // TODO Auto-generated method stub  
  44.         return mList.get(position);  
  45.     }  
  46.   
  47.     public long getItemId(int position) {  
  48.         // TODO Auto-generated method stub  
  49.         return position;  
  50.     }  
  51.   
  52.     public View getView(int position, View convertView, ViewGroup parent) {  
  53.         // TODO Auto-generated method stub  
  54.         Map appInfo = mList.get(position);  
  55.         AppItem appItem;  
  56.         if (convertView == null) {  
  57.             View v = LayoutInflater.from(mContext).inflate(R.layout.app_item, null);  
  58.               
  59.             appItem = new AppItem();  
  60.             appItem.mAppIcon = (ImageView)v.findViewById(R.id.imgdetail);  
  61.             appItem.mAppName = (TextView)v.findViewById(R.id.tuaninfo);  
  62.               
  63.             v.setTag(appItem);  
  64.             convertView = v;  
  65.         } else {  
  66.             appItem = (AppItem)convertView.getTag();  
  67.         }  
  68.         // set the icon  
  69.         appItem.mAppIcon.setImageResource(R.drawable.icon);  
  70.         // set the app name  
  71.         appItem.mAppName.setText(appInfo.get("name").toString());  
  72.           
  73.         return convertView;  
  74.     }  
  75.   
  76.     /** 
  77.      * 每个应用显示的内容,包括图标和名称 
  78.      * @author Yao.GUET 
  79.      * 
  80.      */  
  81.     class AppItem {  
  82.         ImageView mAppIcon;  
  83.         TextView mAppName;  
  84.     }  
  85. }  

Java代码  收藏代码
  1. package cn.anycall.ju;  
  2.   
  3.   
  4.   
  5. import android.content.Context;  
  6. import android.util.AttributeSet;  
  7. import android.widget.ImageView;  
  8. import android.widget.LinearLayout;  
  9. import cn.anycall.ju.R;  
  10. import cn.anycall.ju.ScrollLayout.OnScreenChangeListener;  
  11.   
  12.   
  13.   
  14.   
  15. public class PageControlView extends LinearLayout {  
  16.     private Context context;  
  17.   
  18.     private int count;  
  19.   
  20.     public void bindScrollViewGroup(ScrollLayout scrollViewGroup) {  
  21.         this.count=scrollViewGroup.getChildCount();  
  22.         System.out.println("count="+count);  
  23.         generatePageControl(scrollViewGroup.getCurrentScreenIndex());  
  24.           
  25.         scrollViewGroup.setOnScreenChangeListener(new OnScreenChangeListener() {  
  26.               
  27.             public void onScreenChange(int currentIndex) {  
  28.                 // TODO Auto-generated method stub  
  29.                 generatePageControl(currentIndex);  
  30.             }  
  31.         });  
  32.     }  
  33.   
  34.     public PageControlView(Context context) {  
  35.         super(context);  
  36.         this.init(context);  
  37.     }  
  38.     public PageControlView(Context context, AttributeSet attrs) {  
  39.         super(context, attrs);  
  40.         this.init(context);  
  41.     }  
  42.   
  43.     private void init(Context context) {  
  44.         this.context=context;  
  45.     }  
  46.   
  47.     private void generatePageControl(int currentIndex) {  
  48.         this.removeAllViews();  
  49.   
  50.         int pageNum = 6// 显示多少个   
  51.         int pageNo = currentIndex+1//第几页  
  52.         int pageSum = this.count; //总共多少页  
  53.           
  54.           
  55.         if(pageSum>1){  
  56.             int currentNum = (pageNo % pageNum == 0 ? (pageNo / pageNum) - 1    
  57.                      : (int) (pageNo / pageNum))     
  58.                      * pageNum;   
  59.               
  60.              if (currentNum < 0)     
  61.                  currentNum = 0;     
  62.                
  63.              if (pageNo > pageNum){  
  64.                  ImageView imageView = new ImageView(context);  
  65.                  imageView.setImageResource(R.drawable.zuo);  
  66.                  this.addView(imageView);  
  67.              }  
  68.                
  69.                
  70.                
  71.              for (int i = 0; i < pageNum; i++) {     
  72.                  if ((currentNum + i + 1) > pageSum || pageSum < 2)     
  73.                      break;     
  74.                    
  75.                  ImageView imageView = new ImageView(context);  
  76.                  if(currentNum + i + 1 == pageNo){  
  77.                      imageView.setImageResource(R.drawable.page_indicator_focused);  
  78.                  }else{  
  79.                      imageView.setImageResource(R.drawable.page_indicator);  
  80.                  }  
  81.                  this.addView(imageView);  
  82.              }     
  83.                
  84.              if (pageSum > (currentNum + pageNum)) {  
  85.                  ImageView imageView = new ImageView(context);  
  86.                  imageView.setImageResource(R.drawable.you);  
  87.                  this.addView(imageView);  
  88.              }  
  89.         }  
  90.     }  
  91. }  

Java代码  收藏代码
  1. package cn.anycall.ju;  
  2.   
  3. import android.content.Context;  
  4. import android.graphics.Canvas;  
  5. import android.util.AttributeSet;  
  6. import android.util.Log;  
  7. import android.view.MotionEvent;  
  8. import android.view.VelocityTracker;  
  9. import android.view.View;  
  10. import android.view.ViewConfiguration;  
  11. import android.view.ViewGroup;  
  12. import android.widget.Scroller;  
  13.   
  14. /** 
  15.  * 仿Launcher中的WorkSapce,可以左右滑动切换屏幕的类 
  16.  *  
  17.  */  
  18. public class ScrollLayout extends ViewGroup {  
  19.   
  20.     private static final String TAG = "ScrollLayout";  
  21.     private Scroller mScroller;  
  22.     private VelocityTracker mVelocityTracker;  
  23.   
  24.     private int mCurScreen;  
  25.     private int mDefaultScreen = 0;  
  26.   
  27.     private static final int TOUCH_STATE_REST = 0;  
  28.     private static final int TOUCH_STATE_SCROLLING = 1;  
  29.   
  30.     private static final int SNAP_VELOCITY = 600;  
  31.   
  32.     private int mTouchState = TOUCH_STATE_REST;  
  33.     private int mTouchSlop;  
  34.     private float mLastMotionX;  
  35.     private float mLastMotionY;  
  36.   
  37.     private int currentScreenIndex = 0;  
  38.   
  39.     public int getCurrentScreenIndex() {  
  40.         return currentScreenIndex;  
  41.     }  
  42.   
  43.     public void setCurrentScreenIndex(int currentScreenIndex) {  
  44.         this.currentScreenIndex = currentScreenIndex;  
  45.     }  
  46.   
  47.     public ScrollLayout(Context context, AttributeSet attrs) {  
  48.         this(context, attrs, 0);  
  49.         // TODO Auto-generated constructor stub  
  50.     }  
  51.   
  52.     public ScrollLayout(Context context, AttributeSet attrs, int defStyle) {  
  53.         super(context, attrs, defStyle);  
  54.         // TODO Auto-generated constructor stub  
  55.         mScroller = new Scroller(context);  
  56.   
  57.         mCurScreen = mDefaultScreen;  
  58.         mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();  
  59.     }  
  60.   
  61.     @Override  
  62.     protected void onLayout(boolean changed, int l, int t, int r, int b) {  
  63.         // TODO Auto-generated method stub  
  64.         int childLeft = 0;  
  65.         final int childCount = getChildCount();  
  66.         System.out.println("childCount=" + childCount);  
  67.         for (int i = 0; i < childCount; i++) {  
  68.             final View childView = getChildAt(i);  
  69.             if (childView.getVisibility() != View.GONE) {  
  70.                 final int childWidth = childView.getMeasuredWidth();  
  71.                 childView.layout(childLeft, 0, childLeft + childWidth,  
  72.                         childView.getMeasuredHeight());  
  73.                 childLeft += childWidth;  
  74.             }  
  75.         }  
  76.     }  
  77.   
  78.     @Override  
  79.     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
  80.         Log.e(TAG, "onMeasure");  
  81.         super.onMeasure(widthMeasureSpec, heightMeasureSpec);  
  82.   
  83.         final int width = MeasureSpec.getSize(widthMeasureSpec);  
  84.         final int widthMode = MeasureSpec.getMode(widthMeasureSpec);  
  85.         if (widthMode != MeasureSpec.EXACTLY) {  
  86.             throw new IllegalStateException(  
  87.                     "ScrollLayout only canmCurScreen run at EXACTLY mode!");  
  88.         }  
  89.   
  90.         final int heightMode = MeasureSpec.getMode(heightMeasureSpec);  
  91.         if (heightMode != MeasureSpec.EXACTLY) {  
  92.             throw new IllegalStateException(  
  93.                     "ScrollLayout only can run at EXACTLY mode!");  
  94.         }  
  95.   
  96.         // The children are given the same width and height as the scrollLayout  
  97.         final int count = getChildCount();  
  98.         for (int i = 0; i < count; i++) {  
  99.             getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);  
  100.         }  
  101.         System.out.println("moving to screen " + mCurScreen);  
  102.         scrollTo(mCurScreen * width, 0);  
  103.     }  
  104.   
  105.     /** 
  106.      * According to the position of current layout scroll to the destination 
  107.      * page. 
  108.      */  
  109.     public void snapToDestination() {  
  110.         final int screenWidth = getWidth();  
  111.         final int destScreen = (getScrollX() + screenWidth / 2) / screenWidth;  
  112.         snapToScreen(destScreen);  
  113.     }  
  114.   
  115.     public void snapToScreen(int whichScreen) {  
  116.         // get the valid layout page  
  117.         whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));  
  118.         if (getScrollX() != (whichScreen * getWidth())) {  
  119.   
  120.             final int delta = whichScreen * getWidth() - getScrollX();  
  121.             mScroller.startScroll(getScrollX(), 0, delta, 0,  
  122.                     Math.abs(delta) * 2);  
  123.             mCurScreen = whichScreen;  
  124.             invalidate(); // Redraw the layout  
  125.         }  
  126.     }  
  127.   
  128.     public void setToScreen(int whichScreen) {  
  129.         whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));  
  130.         mCurScreen = whichScreen;  
  131.         scrollTo(whichScreen * getWidth(), 0);  
  132.     }  
  133.   
  134.     public int getCurScreen() {  
  135.         return mCurScreen;  
  136.     }  
  137.   
  138.     @Override  
  139.     public void computeScroll() {  
  140.         // TODO Auto-generated method stub  
  141.         if (mScroller.computeScrollOffset()) {  
  142.             scrollTo(mScroller.getCurrX(), mScroller.getCurrY());  
  143.             postInvalidate();  
  144.         }  
  145.     }  
  146.   
  147.     @Override  
  148.     public boolean onTouchEvent(MotionEvent event) {  
  149.         // TODO Auto-generated method stub  
  150.   
  151.         if (mVelocityTracker == null) {  
  152.             mVelocityTracker = VelocityTracker.obtain();  
  153.         }  
  154.         mVelocityTracker.addMovement(event);  
  155.   
  156.         final int action = event.getAction();  
  157.         final float x = event.getX();  
  158.         final float y = event.getY();  
  159.   
  160.         switch (action) {  
  161.         case MotionEvent.ACTION_DOWN:  
  162.             Log.e(TAG, "event down!");  
  163.             if (!mScroller.isFinished()) {  
  164.                 mScroller.abortAnimation();  
  165.             }  
  166.             mLastMotionX = x;  
  167.             break;  
  168.   
  169.         case MotionEvent.ACTION_MOVE:  
  170.             int deltaX = (int) (mLastMotionX - x);  
  171.             mLastMotionX = x;  
  172.   
  173.             scrollBy(deltaX, 0);  
  174.             break;  
  175.   
  176.         case MotionEvent.ACTION_UP:  
  177.             Log.e(TAG, "event : up");  
  178.   
  179.             // if (mTouchState == TOUCH_STATE_SCROLLING) {  
  180.             final VelocityTracker velocityTracker = mVelocityTracker;  
  181.             velocityTracker.computeCurrentVelocity(1000);  
  182.             int velocityX = (int) velocityTracker.getXVelocity();  
  183.   
  184.             Log.e(TAG, "velocityX:" + velocityX);  
  185.   
  186.             if (velocityX > SNAP_VELOCITY && mCurScreen > 0) {  
  187.                 // Fling enough to move left  
  188.                 Log.e(TAG, "snap left");  
  189.                 onScreenChangeListener.onScreenChange(mCurScreen - 1);  
  190.                 System.out.println("mCurScreen=" + (mCurScreen - 1));  
  191.                 snapToScreen(mCurScreen - 1);  
  192.             } else if (velocityX < -SNAP_VELOCITY  
  193.                     && mCurScreen < getChildCount() - 1) {  
  194.                 // Fling enough to move right  
  195.                 Log.e(TAG, "snap right");  
  196.                 onScreenChangeListener.onScreenChange(mCurScreen + 1);  
  197.                 //只往右移动才加载数据  
  198.                 onScreenChangeListenerDataLoad.onScreenChange(mCurScreen+1);  
  199.                 snapToScreen(mCurScreen + 1);  
  200.             } else {  
  201.                 snapToDestination();  
  202.             }  
  203.   
  204.             if (mVelocityTracker != null) {  
  205.                 mVelocityTracker.recycle();  
  206.                 mVelocityTracker = null;  
  207.             }  
  208.             // }  
  209.             mTouchState = TOUCH_STATE_REST;  
  210.             break;  
  211.         case MotionEvent.ACTION_CANCEL:  
  212.             mTouchState = TOUCH_STATE_REST;  
  213.             break;  
  214.         }  
  215.   
  216.         return true;  
  217.     }  
  218.   
  219.     @Override  
  220.     public boolean onInterceptTouchEvent(MotionEvent ev) {  
  221.         // TODO Auto-generated method stub  
  222.         Log.e(TAG, "onInterceptTouchEvent-slop:" + mTouchSlop);  
  223.   
  224.         final int action = ev.getAction();  
  225.         if ((action == MotionEvent.ACTION_MOVE)  
  226.                 && (mTouchState != TOUCH_STATE_REST)) {  
  227.             return true;  
  228.         }  
  229.   
  230.         final float x = ev.getX();  
  231.         final float y = ev.getY();  
  232.   
  233.         switch (action) {  
  234.         case MotionEvent.ACTION_MOVE:  
  235.             final int xDiff = (int) Math.abs(mLastMotionX - x);  
  236.             if (xDiff > mTouchSlop) {  
  237.                 mTouchState = TOUCH_STATE_SCROLLING;  
  238.   
  239.             }  
  240.             break;  
  241.   
  242.         case MotionEvent.ACTION_DOWN:  
  243.             mLastMotionX = x;  
  244.             mLastMotionY = y;  
  245.             mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST  
  246.                     : TOUCH_STATE_SCROLLING;  
  247.             break;  
  248.   
  249.         case MotionEvent.ACTION_CANCEL:  
  250.         case MotionEvent.ACTION_UP:  
  251.             mTouchState = TOUCH_STATE_REST;  
  252.             break;  
  253.         }  
  254.   
  255.         return mTouchState != TOUCH_STATE_REST;  
  256.     }  
  257.   
  258.     //分页监听  
  259.     public interface OnScreenChangeListener {  
  260.         void onScreenChange(int currentIndex);  
  261.     }  
  262.   
  263.     private OnScreenChangeListener onScreenChangeListener;  
  264.   
  265.     public void setOnScreenChangeListener(  
  266.             OnScreenChangeListener onScreenChangeListener) {  
  267.         this.onScreenChangeListener = onScreenChangeListener;  
  268.     }  
  269.       
  270.       
  271.     //动态数据监听  
  272.     public interface OnScreenChangeListenerDataLoad {  
  273.         void onScreenChange(int currentIndex);  
  274.     }  
  275.     private OnScreenChangeListenerDataLoad onScreenChangeListenerDataLoad;  
  276.   
  277.     public void setOnScreenChangeListenerDataLoad(OnScreenChangeListenerDataLoad onScreenChangeListenerDataLoad) {  
  278.         this.onScreenChangeListenerDataLoad = onScreenChangeListenerDataLoad;  
  279.     }  
  280.   
  281. }  



main.xml
Xml代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"   
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7.     <TextView android:layout_width="fill_parent"  
  8.         android:layout_height="wrap_content"  android:text="仿淘宝聚划算"/>  
  9. <RelativeLayout  
  10.     android:id="@+id/myView"  
  11.     android:layout_width="fill_parent"  
  12.     android:layout_height="fill_parent"   
  13.     >  
  14. <cn.anycall.ju.ScrollLayout  
  15.   xmlns:android="http://schemas.android.com/apk/res/android"  
  16.   android:id="@+id/ScrollLayoutTest"  
  17.   android:layout_width="fill_parent"  
  18.   android:layout_height="fill_parent"  android:background="#000000" >  
  19. </cn.anycall.ju.ScrollLayout>  
  20.   
  21. <cn.anycall.ju.PageControlView   
  22.                 android:id="@+id/pageControl"  
  23.                 android:layout_width="fill_parent"   
  24.                 android:layout_height="40px"  
  25.                 android:background="#8f00000f"   
  26.                 android:layout_alignParentBottom="true"  
  27.                 android:gravity="center"/>  
  28. </RelativeLayout>  
  29. </LinearLayout>  

app_item.xml
Xml代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   
  3. android:layout_width="fill_parent"   
  4. android:layout_height="wrap_content"   
  5. >   
  6. <RelativeLayout android:id="@+id/alllayout" android:layout_width="wrap_content"  android:layout_height="wrap_content">  
  7.      <RelativeLayout android:id="@+id/imglayout" android:layout_width="160dp"  android:layout_height="160dp" android:background="@drawable/mer_border">  
  8.                 <ImageView android:id="@+id/imgdetail" android:layout_width="145dp"  android:layout_height="145dp" android:layout_margin="8dp" />  
  9.                 <TextView android:id="@+id/price" android:layout_width="180dp"  android:layout_height="wrap_content" android:text="12345" android:layout_alignParentBottom="true" android:background="#C02000" android:textColor="#FFFFFF"/>  
  10.                 <TextView android:id="@+id/look" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="去看看" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:background="#C02000" android:textColor="#FFFFFF"/>  
  11.       </RelativeLayout>  
  12.       <TextView android:id="@+id/tuaninfo" android:layout_width="fill_parent"   
  13.       android:layout_height="wrap_content" android:textSize="16dp"   
  14.       android:maxLines="2" android:layout_below="@id/imglayout"   
  15.        android:ellipsize="end" android:text="dddddddddd"/>"  
  16. </RelativeLayout>  
  17. </RelativeLayout>