コード例 #1
1
 /**
  * 设置组件的高度(给父类的宽度为整个屏幕的高度)
  *
  * @param view
  * @param height
  */
 public static void setViewHeight(View view, double height) {
   if (view.getLayoutParams() == null) {
     view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, (int) (screenH * height)));
   } else {
     view.getLayoutParams().height = (int) (screenH * height);
   }
 }
コード例 #2
1
 /**
  * 设置组件的宽度(给父类的宽度为整个屏幕的宽度)
  *
  * @param view(要设置的组件)
  * @param width(所占比例)
  */
 public static void setViewWidth(View view, double width) {
   if (view.getLayoutParams() == null) {
     view.setLayoutParams(new LayoutParams((int) (screenW * width), LayoutParams.WRAP_CONTENT));
   } else {
     view.getLayoutParams().width = (int) (screenW * width);
   }
 }
コード例 #3
1
  private void recomputePhotoAndScrollingMetrics() {
    mHeaderHeightPixels = mHeaderBox.getHeight();

    mPhotoHeightPixels = 0;
    if (mHasPhoto) {
      mPhotoHeightPixels = (int) (mPhotoView.getWidth() / PHOTO_ASPECT_RATIO);
      mPhotoHeightPixels = Math.min(mPhotoHeightPixels, mScrollView.getHeight() * 2 / 3);
    }

    ViewGroup.LayoutParams lp;
    lp = mPhotoViewContainer.getLayoutParams();
    if (lp.height != mPhotoHeightPixels) {
      lp.height = mPhotoHeightPixels;
      mPhotoViewContainer.setLayoutParams(lp);
    }

    ViewGroup.MarginLayoutParams mlp =
        (ViewGroup.MarginLayoutParams) mDetailsContainer.getLayoutParams();
    if (mlp.topMargin != mHeaderHeightPixels + mPhotoHeightPixels) {
      mlp.topMargin = mHeaderHeightPixels + mPhotoHeightPixels;
      mDetailsContainer.setLayoutParams(mlp);
    }

    onScrollChanged(0, 0); // trigger scroll handling
  }
コード例 #4
1
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int count = getChildCount();

    int offsetX = 0;
    if (mCenterContent && count > 0) {
      // determine the max width of all the rows and center accordingly
      int maxRowX = 0;
      int minRowX = Integer.MAX_VALUE;
      for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
          PagedViewCellLayout.LayoutParams lp =
              (PagedViewCellLayout.LayoutParams) child.getLayoutParams();
          minRowX = Math.min(minRowX, lp.x);
          maxRowX = Math.max(maxRowX, lp.x + lp.width);
        }
      }
      int maxRowWidth = maxRowX - minRowX;
      offsetX = (getMeasuredWidth() - maxRowWidth) / 2;
    }

    for (int i = 0; i < count; i++) {
      View child = getChildAt(i);
      if (child.getVisibility() != GONE) {
        PagedViewCellLayout.LayoutParams lp =
            (PagedViewCellLayout.LayoutParams) child.getLayoutParams();

        int childLeft = offsetX + lp.x;
        int childTop = lp.y;
        child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
      }
    }
  }
コード例 #5
1
 /**
  * 横向container之间添加横线
  *
  * @param context
  * @return
  */
 public static View addViewlines(Context context, int width, int height) {
   View view = LayoutInflater.from(context).inflate(R.layout.viewline, null);
   ViewUtil.setViewWidth(view, width, 1);
   view.getLayoutParams().height = 1;
   Log.e("height", view.getLayoutParams().height + "");
   return view;
 }
コード例 #6
1
  /**
   * Transform the Image Bitmap by the Angle passed
   *
   * @param imageView ImageView the ImageView whose bitmap we want to rotate
   * @param t transformation
   * @param rotationAngle the Angle by which to rotate the Bitmap
   */
  private void transformBitmap(View child, Transformation t, int rotationAngle) {

    final Matrix childMatrix = t.getMatrix();
    final int childHeight = child.getLayoutParams().height;
    final int childWidth = child.getLayoutParams().width;
    final int rotation = Math.abs(rotationAngle);

    mCamera.save();
    mCamera.translate(0.0f, 0.0f, 100.0f);
    // As the angle of the view gets less, zoom in
    if (rotation <= mMaxRotationAngle) {
      float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
      mCamera.translate(0.0f, 0.0f, zoomAmount);
      if (mCircleMode) {
        if (rotation < 40) mCamera.translate(0.0f, 155, 0.0f);
        else mCamera.translate(0.0f, (255 - rotation * 2.5f), 0.0f);
      }
      if (mAlphaMode) {
        ((ImageView) (child)).setAlpha((int) (255 - rotation * 2.5));
      }
    }
    mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(childMatrix);
    childMatrix.preTranslate(-(childWidth / 2), -(childHeight / 2));
    childMatrix.postTranslate((childWidth / 2), (childHeight / 2));
    mCamera.restore();
  }
コード例 #7
0
ファイル: TopDrawerLayout.java プロジェクト: kendada/Qzone
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthSie = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    setMeasuredDimension(widthSie, heightSize);

    View bottomView = getChildAt(1);
    MarginLayoutParams lp = (MarginLayoutParams) bottomView.getLayoutParams();
    int drawerWidthSpec =
        getChildMeasureSpec(widthMeasureSpec, lp.leftMargin + lp.rightMargin, lp.width);
    int drawerHeightSpec =
        getChildMeasureSpec(heightMeasureSpec, lp.bottomMargin + lp.topMargin, lp.height);

    bottomView.measure(drawerWidthSpec, drawerHeightSpec);

    View contentView = getChildAt(0);
    lp = (MarginLayoutParams) contentView.getLayoutParams();
    int contentWidthSpec =
        MeasureSpec.makeMeasureSpec(widthSie - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
    int contentHeightSpec =
        MeasureSpec.makeMeasureSpec(
            heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
    contentView.measure(contentWidthSpec, contentHeightSpec);

    mBottomMenuView = bottomView;
    mContentView = contentView;
  }
コード例 #8
0
ファイル: Toolbar.java プロジェクト: sheytoon/Fanoos
 private void a(List list, int i) {
     int i2 = 1;
     int i3 = 0;
     if (hg.g(this) != 1) {
         i2 = 0;
     }
     int childCount = getChildCount();
     int a = fv.a(i, hg.g(this));
     list.clear();
     LayoutParams layoutParams;
     if (i2 != 0) {
         for (i3 = childCount - 1; i3 >= 0; i3--) {
             View childAt = getChildAt(i3);
             layoutParams = (LayoutParams) childAt.getLayoutParams();
             if (layoutParams.b == 0 && b(childAt) && b(layoutParams.a) == a) {
                 list.add(childAt);
             }
         }
         return;
     }
     while (i3 < childCount) {
         View childAt2 = getChildAt(i3);
         layoutParams = (LayoutParams) childAt2.getLayoutParams();
         if (layoutParams.b == 0 && b(childAt2) && b(layoutParams.a) == a) {
             list.add(childAt2);
         }
         i3++;
     }
 }
コード例 #9
0
ファイル: BaseHelper.java プロジェクト: final60/geoalertapp
 public static void setMargins(View view, int left, int top, int right, int bottom) {
   if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
     ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
     p.setMargins(left, top, right, bottom);
     view.requestLayout();
   }
 }
コード例 #10
0
ファイル: Gallery3D.java プロジェクト: gaoge/gaoge
 /**
  * Transform the Image Bitmap by the Angle passed
  *
  * @param imageView ImageView the ImageView whose bitmap we want to rotate
  * @param t transformation
  * @param rotationAngle the Angle by which to rotate the Bitmap
  */
 private void transformImageBitmap(View child, Transformation t, int rotationAngle, int d) {
   mCamera.save();
   final Matrix imageMatrix = t.getMatrix();
   final int imageHeight = child.getLayoutParams().height;
   final int imageWidth = child.getLayoutParams().width;
   final int rotation = Math.abs(rotationAngle);
   // mCamera.translate(0.0f, 0.0f, 100.0f);
   // As the angle of the view gets less, zoom in
   // if (rotation <= mMaxRotationAngle) {
   float zoomAmount = (float) (-140 + (rotation * 2));
   if (rotationAngle < 0) {
     mCamera.translate((float) (-rotation * 0.5), (float) (-rotation * 0.3) + 5, zoomAmount);
   } else {
     mCamera.translate((float) rotation, (float) (-rotation * 0.3) + 5, zoomAmount);
   }
   Log.i("info", "---------------------->" + rotationAngle);
   if (mCircleMode) {
     if (rotation < 40) {
       mCamera.translate(0.0f, 155, 0.0f);
     } else {
       mCamera.translate(0.0f, (255 - rotation * 2.5f), 0.0f);
     }
   }
   if (mAlphaMode) {
     // child.setBackgroundDrawable(getResources().getDrawable(R.drawable.app_bg));
     // child.setBackgroundColor(255);
   }
   // }
   // mCamera.rotateY(rotationAngle);
   mCamera.getMatrix(imageMatrix);
   imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
   imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
   mCamera.restore();
 }
コード例 #11
0
  @Override
  public void call(final Subscriber<? super View> subscriber) {
    verifyMainThread();

    SwipeDismissBehavior.OnDismissListener listener =
        new SwipeDismissBehavior.OnDismissListener() {
          @Override
          public void onDismiss(View view) {
            if (!subscriber.isUnsubscribed()) {
              subscriber.onNext(view);
            }
          }

          @Override
          public void onDragStateChanged(int i) {}
        };

    if (!(view.getLayoutParams() instanceof LayoutParams)) {
      throw new IllegalArgumentException("The view is not in a Coordinator Layout.");
    }
    LayoutParams params = (LayoutParams) view.getLayoutParams();
    final SwipeDismissBehavior behavior = (SwipeDismissBehavior) params.getBehavior();
    if (behavior == null) {
      throw new IllegalStateException("There's no behavior set on this view.");
    }
    behavior.setListener(listener);

    subscriber.add(
        new MainThreadSubscription() {
          @Override
          protected void onUnsubscribe() {
            behavior.setListener(null);
          }
        });
  }
コード例 #12
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    LogUtil.i("MoveLinearLayout", "[onMeasure] start");
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int count = getChildCount();
    boolean sub2 = false, sub3 = false;
    View view;
    for (int i = 0; i < count; ++i) {
      view = getChildAt(i);

      if (view.getId() == R.id.sub_view_1) {
        LogUtil.i(
            "MoveLinearLayout", "[onMeasure] sub_view_1  widthMeasureSpec : " + widthMeasureSpec);
      }
      if (view.getId() == R.id.sub_view_2 && !sub2) {
        LogUtil.i(
            "MoveLinearLayout", "[onMeasure] sub_view_2  widthMeasureSpec : " + widthMeasureSpec);
        view.setLayoutParams(new LayoutParams(widthMeasureSpec, view.getLayoutParams().height));
        sub2 = true;
      }
      if (view.getId() == R.id.sub_view_3 && sub3 == false) {
        LogUtil.i(
            "MoveLinearLayout", "[onMeasure] : sub_view_3 widthMeasureSpec : " + widthMeasureSpec);
        view.setLayoutParams(new LayoutParams(widthMeasureSpec, view.getLayoutParams().height));
        sub3 = true;
      }
      if (sub2 && sub3) {
        break;
      }
    }
  }
コード例 #13
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    FrameLayout.LayoutParams lp = (LayoutParams) mContentView.getLayoutParams();
    int lGap = getPaddingLeft() + lp.leftMargin;
    int tGap = getPaddingTop() + lp.topMargin;
    mContentView.layout(
        lGap,
        tGap,
        lGap
            + (OVER_API_11
                ? mContentView.getMeasuredWidthAndState()
                : mContentView.getMeasuredWidth()),
        tGap
            + (OVER_API_11
                ? mContentView.getMeasuredHeightAndState()
                : mContentView.getMeasuredHeight()));

    lp = (LayoutParams) mMenuView.getLayoutParams();
    tGap = getPaddingTop() + lp.topMargin;
    if (mSwipeDirection == SwipeMenuRecyclerView.DIRECTION_LEFT) {
      mMenuView.layout(
          getMeasuredWidth(),
          tGap,
          getMeasuredWidth()
              + (OVER_API_11 ? mMenuView.getMeasuredWidthAndState() : mMenuView.getMeasuredWidth()),
          tGap + mMenuView.getMeasuredHeightAndState());
    } else {
      mMenuView.layout(
          -(OVER_API_11 ? mMenuView.getMeasuredWidthAndState() : mMenuView.getMeasuredWidth()),
          tGap,
          0,
          tGap + mMenuView.getMeasuredHeightAndState());
    }
  }
コード例 #14
0
ファイル: PtrFrameLayout.java プロジェクト: zhaoyu87/MyGuokr
  private void layoutChildren() {
    int offsetX = mPtrIndicator.getCurrentPosY();
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();

    if (mHeaderView != null) {
      MarginLayoutParams lp = (MarginLayoutParams) mHeaderView.getLayoutParams();
      final int left = paddingLeft + lp.leftMargin;
      final int top = paddingTop + lp.topMargin + offsetX - mHeaderHeight;
      final int right = left + mHeaderView.getMeasuredWidth();
      final int bottom = top + mHeaderView.getMeasuredHeight();
      mHeaderView.layout(left, top, right, bottom);
      if (DEBUG && DEBUG_LAYOUT) {
        PtrCLog.d(LOG_TAG, "onLayout header: %s %s %s %s", left, top, right, bottom);
      }
    }
    if (mContent != null) {
      if (isPinContent()) {
        offsetX = 0;
      }
      MarginLayoutParams lp = (MarginLayoutParams) mContent.getLayoutParams();
      final int left = paddingLeft + lp.leftMargin;
      final int top = paddingTop + lp.topMargin + offsetX;
      final int right = left + mContent.getMeasuredWidth();
      final int bottom = top + mContent.getMeasuredHeight();
      if (DEBUG && DEBUG_LAYOUT) {
        PtrCLog.d(LOG_TAG, "onLayout content: %s %s %s %s", left, top, right, bottom);
      }
      mContent.layout(left, top, right, bottom);
    }
  }
 void drawDividersVertical(Canvas paramCanvas)
 {
   int j = getVirtualChildCount();
   int i = 0;
   View localView;
   LinearLayoutCompat.LayoutParams localLayoutParams;
   while (i < j)
   {
     localView = getVirtualChildAt(i);
     if ((localView != null) && (localView.getVisibility() != 8) && (hasDividerBeforeChildAt(i)))
     {
       localLayoutParams = (LinearLayoutCompat.LayoutParams)localView.getLayoutParams();
       drawHorizontalDivider(paramCanvas, localView.getTop() - topMargin - mDividerHeight);
     }
     i += 1;
   }
   if (hasDividerBeforeChildAt(j))
   {
     localView = getVirtualChildAt(j - 1);
     if (localView != null) {
       break label124;
     }
   }
   for (i = getHeight() - getPaddingBottom() - mDividerHeight;; i = bottomMargin + i)
   {
     drawHorizontalDivider(paramCanvas, i);
     return;
     label124:
     localLayoutParams = (LinearLayoutCompat.LayoutParams)localView.getLayoutParams();
     i = localView.getBottom();
   }
 }
コード例 #16
0
  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();
    int childCount = getChildCount();
    ViewGroup.LayoutParams params = getLayoutParams();

    ArrayList<View> children = new ArrayList<>();
    View swipeDeck = null;
    for (int i = 0; i < childCount; ++i) {
      View child = getChildAt(i);
      if (child instanceof SwipeDeck) {
        swipeDeck = getChildAt(i);
      } else {
        children.add(child);
      }
    }
    removeAllViews();
    removeAllViewsInLayout();
    for (View v : children) {
      addViewInLayout(v, -1, v.getLayoutParams(), true);
    }
    if (swipeDeck != null) {
      addViewInLayout(swipeDeck, -1, swipeDeck.getLayoutParams(), true);
    }
    invalidate();
    requestLayout();
  }
コード例 #17
0
 @Override
 protected void execute(View view, int val) {
   if (!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) {
     return;
   }
   ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
   lp.rightMargin = val;
 }
コード例 #18
0
 /**
  * 设置组件的宽高
  *
  * @param view
  * @param width
  * @param height
  */
 public static void setViewWidHeight(View view, double width, double height) {
   if (view.getLayoutParams() == null) {
     view.setLayoutParams(new LayoutParams((int) (screenW * width), (int) (screenH * height)));
   } else {
     view.getLayoutParams().width = (int) (screenW * width);
     view.getLayoutParams().height = (int) (screenH * height);
   }
 }
コード例 #19
0
  private void setupStandardButtonOutline() {
    Outline roundRectOutline = new Outline();
    roundRectOutline.setRoundRect(
        0, 0, standardButton.getLayoutParams().width, standardButton.getLayoutParams().height, 20);

    standardButton.setOutline(roundRectOutline);
    standardButton.setClipToOutline(true);
  }
コード例 #20
0
ファイル: ViewsTest.java プロジェクト: wentaotao/android-base
  @Test
  public void testSetHeight() throws Exception {
    final View view = new View(RuntimeEnvironment.application);
    view.setLayoutParams(new ViewGroup.LayoutParams(25, 50));
    assertThat(view.getLayoutParams()).hasHeight(50);

    Views.setHeight(view, 500);
    assertThat(view.getLayoutParams()).hasHeight(500);
  }
コード例 #21
0
  // suppress this error message to be able to use spaces in higher api levels
  @SuppressLint("NewApi")
  public void refresh() {

    if (mAdapter == null) {
      mAdapter = new StackAdapter(mContext, mStacks, mSwipeable);
      if (mListView != null) {
        mListView.setAdapter(mAdapter);
      } else if (mTableLayout != null) {
        TableRow tr = null;
        for (int i = 0; i < mAdapter.getCount(); i += mColumnNumber) {
          // add a new table row with the current context
          tr = new TableRow(mTableLayout.getContext());
          tr.setOrientation(TableRow.HORIZONTAL);
          tr.setLayoutParams(
              new TableRow.LayoutParams(
                  TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
          // add as many cards as the number of columns indicates per row
          for (int j = 0; j < mColumnNumber; j++) {
            if (i + j < mAdapter.getCount()) {
              View card = mAdapter.getView(i + j, null, tr);
              if (card.getLayoutParams() != null) {
                card.setLayoutParams(
                    new TableRow.LayoutParams(
                        card.getLayoutParams().width, card.getLayoutParams().height, 1f));
              } else {
                card.setLayoutParams(
                    new TableRow.LayoutParams(
                        TableRow.LayoutParams.MATCH_PARENT,
                        TableRow.LayoutParams.WRAP_CONTENT,
                        1f));
              }
              tr.addView(card);
            }
          }
          mTableLayout.addView(tr);
        }
        if (tr != null) {
          // fill the empty space with spacers
          for (int j = mAdapter.getCount() % mColumnNumber; j > 0; j--) {
            View space = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
              space = new Space(tr.getContext());
            } else {
              space = new View(tr.getContext());
            }
            space.setLayoutParams(
                new TableRow.LayoutParams(
                    TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
            tr.addView(space);
          }
        }
      }
    } else {
      mAdapter.setSwipeable(mSwipeable); // in case swipeable changed;
      mAdapter.setItems(mStacks);
    }
  }
 void drawDividersHorizontal(Canvas paramCanvas)
 {
   int k = getVirtualChildCount();
   boolean bool = ViewUtils.isLayoutRtl(this);
   int i = 0;
   View localView;
   LinearLayoutCompat.LayoutParams localLayoutParams;
   if (i < k)
   {
     localView = getVirtualChildAt(i);
     if ((localView != null) && (localView.getVisibility() != 8) && (hasDividerBeforeChildAt(i)))
     {
       localLayoutParams = (LinearLayoutCompat.LayoutParams)localView.getLayoutParams();
       if (!bool) {
         break label92;
       }
       j = localView.getRight();
     }
     label92:
     for (int j = rightMargin + j;; j = localView.getLeft() - leftMargin - mDividerWidth)
     {
       drawVerticalDivider(paramCanvas, j);
       i += 1;
       break;
     }
   }
   if (hasDividerBeforeChildAt(k))
   {
     localView = getVirtualChildAt(k - 1);
     if (localView != null) {
       break label171;
     }
     if (!bool) {
       break label153;
     }
     i = getPaddingLeft();
   }
   for (;;)
   {
     drawVerticalDivider(paramCanvas, i);
     return;
     label153:
     i = getWidth() - getPaddingRight() - mDividerWidth;
     continue;
     label171:
     localLayoutParams = (LinearLayoutCompat.LayoutParams)localView.getLayoutParams();
     if (bool)
     {
       i = localView.getLeft() - leftMargin - mDividerWidth;
     }
     else
     {
       i = localView.getRight();
       i = rightMargin + i;
     }
   }
 }
コード例 #23
0
  @Override
  public View getView(final int position, View convertView, final ViewGroup parent) {
    int viewType = getItemViewType(position);

    if (viewType == TYPE_CAMERA) {
      CameraViewHolder holder;
      if (convertView == null) {
        convertView = mInflater.inflate(R.layout.media_camera_item, parent, false);
        AbsListView.LayoutParams params = (AbsListView.LayoutParams) convertView.getLayoutParams();
        int width = (mWidth - 2 * getPixelSize(R.dimen.media_item_horizontal_spacing)) / 3;
        params.width = width;
        params.height = width;
        convertView.setLayoutParams(params);

        holder = new CameraViewHolder(convertView);
        convertView.setTag(holder);
      } else {
        holder = (CameraViewHolder) convertView.getTag();
      }
    } else {
      MediaViewHolder holder;
      if (convertView == null) {
        convertView = mInflater.inflate(R.layout.media_item, parent, false);
        AbsListView.LayoutParams params = (AbsListView.LayoutParams) convertView.getLayoutParams();
        int width = (mWidth - 2 * getPixelSize(R.dimen.media_item_horizontal_spacing)) / 3;
        params.width = width;
        params.height = width;
        convertView.setLayoutParams(params);

        holder = new MediaViewHolder(convertView);
        convertView.setTag(holder);
      } else {
        holder = (MediaViewHolder) convertView.getTag();
      }

      final Media media = mMedias.get(position);

      setImage(holder.photoIv, media.getData());
      setIndex(holder.indexTv, contains(media));
      setText(holder.sizeTv, ByteUtil.format(media.getSize()));
      setVisibility(holder.indexTv, true);
      setVisibility(holder.videoLayout, media.getMediaType() == MediaType.MEDIA_TYPE_VIDEO);

      final View view = convertView;
      holder.indexTv.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (mOnItemCheckedListener == null) return;

              mOnItemCheckedListener.onItemChecked(view, position);
            }
          });
    }

    return convertView;
  }
コード例 #24
0
  /**
   * Taken (almost) verbatum from system FrameLayout Completely ignores margins and child states.
   * Should probably only take Card views into account.
   */
  @Override
  protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
    final int count = getChildCount();

    final boolean measureMatchParentChildren =
        MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY
            || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY;
    mMatchParentChildren.clear();

    int maxHeight = 0;
    int maxWidth = 0;

    for (int i = 0; i < count; i++) {
      final View child = getChildAt(i);
      if (child.getVisibility() != GONE) {
        final LayoutParams lp = child.getLayoutParams();
        final int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, lp.width);
        final int childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, 0, lp.height);
        child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
        maxWidth = Math.max(maxWidth, child.getMeasuredWidth());
        maxHeight = Math.max(maxHeight, child.getMeasuredHeight());
        if (measureMatchParentChildren) {
          if (lp.width == LayoutParams.MATCH_PARENT || lp.height == LayoutParams.MATCH_PARENT) {
            mMatchParentChildren.add(child);
          }
        }
      }
    }

    maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
    maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
    setMeasuredDimension(
        resolveSize(maxWidth, widthMeasureSpec), resolveSize(maxHeight, heightMeasureSpec));

    for (final View child : mMatchParentChildren) {
      final LayoutParams lp = child.getLayoutParams();
      int childWidthMeasureSpec;
      int childHeightMeasureSpec;

      if (lp.width == LayoutParams.MATCH_PARENT) {
        childWidthMeasureSpec =
            MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
      } else {
        childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, lp.width);
      }

      if (lp.height == LayoutParams.MATCH_PARENT) {
        childHeightMeasureSpec =
            MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY);
      } else {
        childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, 0, lp.height);
      }

      child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
    }
  }
コード例 #25
0
ファイル: LayoutFragment.java プロジェクト: Kisty/twoway-view
    @Override
    public void onBindViewHolder(SimpleViewHolder holder, int position) {
      holder.title.setText(String.valueOf(position));

      boolean isVertical = (mRecyclerView.getOrientation() == Orientation.VERTICAL);
      final View itemView = holder.itemView;

      if (mLayoutId == R.layout.layout_staggered_grid) {
        final int id;
        if (position % 3 == 0) {
          id = R.dimen.staggered_child_medium;
        } else if (position % 5 == 0) {
          id = R.dimen.staggered_child_large;
        } else if (position % 7 == 0) {
          id = R.dimen.staggered_child_xlarge;
        } else {
          id = R.dimen.staggered_child_small;
        }

        final int span;
        if (position == 2) {
          span = 2;
        } else {
          span = 1;
        }

        final int size = mContext.getResources().getDimensionPixelSize(id);

        final StaggeredGridLayoutManager.LayoutParams lp =
            (StaggeredGridLayoutManager.LayoutParams) itemView.getLayoutParams();
        if (!isVertical && lp.width != id) {
          lp.span = span;
          lp.width = size;
          itemView.setLayoutParams(lp);
        } else if (isVertical && lp.height != id) {
          lp.span = span;
          lp.height = size;
          itemView.setLayoutParams(lp);
        }
      } else if (mLayoutId == R.layout.layout_spannable_grid) {
        final SpannableGridLayoutManager.LayoutParams lp =
            (SpannableGridLayoutManager.LayoutParams) itemView.getLayoutParams();

        final int span1 = (position == 0 || position == 3 ? 2 : 1);
        final int span2 = (position == 0 ? 2 : (position == 3 ? 3 : 1));

        final int colSpan = (isVertical ? span2 : span1);
        final int rowSpan = (isVertical ? span1 : span2);

        if (lp.rowSpan != rowSpan || lp.colSpan != colSpan) {
          lp.rowSpan = rowSpan;
          lp.colSpan = colSpan;
          itemView.setLayoutParams(lp);
        }
      }
    }
コード例 #26
0
 /**
  * 设置组件的宽高
  *
  * @param (要设置的组件)
  * @param groupWidth(父组件的宽度)
  * @param groupHeight(父组件的高度)
  * @param width
  * @param height
  */
 public static void setViewWidHeight(
     View view, double groupWidth, double groupHeight, double width, double height) {
   if (view.getLayoutParams() == null) {
     view.setLayoutParams(
         new LayoutParams((int) ((groupWidth * width)), (int) (groupHeight * height)));
   } else {
     view.getLayoutParams().width = (int) ((groupWidth * width));
     view.getLayoutParams().height = (int) (groupHeight * height);
   }
 }
コード例 #27
0
ファイル: MapFragment.java プロジェクト: dbof10/weathermap
 public void setMapBottomPadding(int bottomPadding) {
   mMapBottomPadding = bottomPadding;
   if (mGoogleMap != null) mGoogleMap.setPadding(0, mToolbar.getHeight(), 0, mMapBottomPadding);
   if (bottomPadding != 0) {
     ((FrameLayout.LayoutParams) mPostButton.getLayoutParams()).bottomMargin = bottomPadding;
   } else {
     ((FrameLayout.LayoutParams) mPostButton.getLayoutParams()).bottomMargin =
         getResources().getDimensionPixelOffset(R.dimen.fab_margin);
   }
 }
コード例 #28
0
ファイル: ChatViewRoot.java プロジェクト: TLemur/SawimNEmod
 public ChatViewRoot(Context context, View chatListsView, View chatInputBarView) {
   super(context);
   setOrientation(LinearLayout.VERTICAL);
   LinearLayout.LayoutParams layoutParams =
       new LinearLayout.LayoutParams(
           LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
   setLayoutParams(layoutParams);
   addViewInLayout(chatListsView, 0, chatListsView.getLayoutParams());
   addViewInLayout(chatInputBarView, 1, chatInputBarView.getLayoutParams());
 }
コード例 #29
0
 public LayoutBar(Context context, int layoutId, Gravity gravity) {
   super();
   this.context = context;
   this.layoutId = layoutId;
   this.view = LayoutInflater.from(context).inflate(layoutId, new LinearLayout(context), false);
   layoutParams = view.getLayoutParams();
   this.height = view.getLayoutParams().height;
   this.width = view.getLayoutParams().width;
   this.gravity = gravity;
 }
コード例 #30
0
  @Override
  public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (mDivider == null) {
      super.onDrawOver(c, parent, state);
      return;
    }

    // Initialization needed to avoid compiler warning
    int left = 0, right = 0, top = 0, bottom = 0, size;
    int orientation = mOrientation != -1 ? mOrientation : getOrientation(parent);
    int childCount = parent.getChildCount();

    if (orientation == LinearLayoutManager.VERTICAL) {
      size = mDivider.getIntrinsicHeight();
      left = parent.getPaddingLeft();
      right = parent.getWidth() - parent.getPaddingRight();
    } else { // horizontal
      size = mDivider.getIntrinsicWidth();
      top = parent.getPaddingTop();
      bottom = parent.getHeight() - parent.getPaddingBottom();
    }

    for (int i = mShowFirstDivider ? 0 : 1; i < childCount; i++) {
      View child = parent.getChildAt(i);
      RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

      if (orientation == LinearLayoutManager.VERTICAL) {
        top = child.getTop() - params.topMargin - size;
        bottom = top + size;
      } else { // horizontal
        left = child.getLeft() - params.leftMargin;
        right = left + size;
      }
      mDivider.setBounds(left, top, right, bottom);
      mDivider.draw(c);
    }

    // show last divider
    if (mShowLastDivider && childCount > 0) {
      View child = parent.getChildAt(childCount - 1);
      if (parent.getChildAdapterPosition(child) == (state.getItemCount() - 1)) {
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        if (orientation == LinearLayoutManager.VERTICAL) {
          top = child.getBottom() + params.bottomMargin;
          bottom = top + size;
        } else { // horizontal
          left = child.getRight() + params.rightMargin;
          right = left + size;
        }
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
      }
    }
  }