Beispiel #1
0
  private void initWithContext(Context context) {
    mLayout = (LinearLayout) View.inflate(context, R.layout.vw_xscrollview_layout, null);
    mContentLayout = (LinearLayout) mLayout.findViewById(R.id.content_layout);

    mScroller = new Scroller(context, new DecelerateInterpolator());
    // XScrollView need the scroll event, and it will dispatch the event to user's listener (as a
    // proxy).
    this.setOnScrollListener(this);

    // init header view
    mHeader = new XHeaderView(context);
    mHeaderContent = (RelativeLayout) mHeader.findViewById(R.id.header_content);
    mHeaderTime = (TextView) mHeader.findViewById(R.id.header_hint_time);
    LinearLayout headerLayout = (LinearLayout) mLayout.findViewById(R.id.header_layout);
    headerLayout.addView(mHeader);

    // init footer view
    mFooterView = new XFooterView(context);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    LinearLayout footLayout = (LinearLayout) mLayout.findViewById(R.id.footer_layout);
    footLayout.addView(mFooterView, params);

    // init header height
    ViewTreeObserver observer = mHeader.getViewTreeObserver();
    if (null != observer) {
      observer.addOnGlobalLayoutListener(
          new OnGlobalLayoutListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @SuppressWarnings("deprecation")
            @Override
            public void onGlobalLayout() {
              mHeaderHeight = mHeaderContent.getHeight();
              ViewTreeObserver observer = getViewTreeObserver();
              if (null != observer) {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                  observer.removeGlobalOnLayoutListener(this);
                } else {
                  observer.removeOnGlobalLayoutListener(this);
                }
              }
            }
          });
    }

    this.addView(mLayout);
  }
  private void initWithContext(Context context) {
    mScroller = new Scroller(context, new DecelerateInterpolator());
    super.setOnScrollListener(this);

    // init header view
    mHeader = new XHeaderView(context);
    mHeaderContent = (RelativeLayout) mHeader.findViewById(R.id.header_content);
    mHeaderTime = (TextView) mHeader.findViewById(R.id.header_hint_time);
    addHeaderView(mHeader);

    // init footer view
    mFooterView = new XFooterView(context);
    mFooterLayout = new LinearLayout(context);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    mFooterLayout.addView(mFooterView, params);

    // init header height
    ViewTreeObserver observer = mHeader.getViewTreeObserver();
    if (null != observer) {
      observer.addOnGlobalLayoutListener(
          new OnGlobalLayoutListener() {
            @SuppressWarnings("deprecation")
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onGlobalLayout() {
              mHeaderHeight = mHeaderContent.getHeight();
              ViewTreeObserver observer = getViewTreeObserver();

              if (null != observer) {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                  observer.removeGlobalOnLayoutListener(this);
                } else {
                  observer.removeOnGlobalLayoutListener(this);
                }
              }
            }
          });
    }
  }