Java Code Examples for android.widget.LinearLayout#VERTICAL

The following examples show how to use android.widget.LinearLayout#VERTICAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeaderRenderer.java    From toktok-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initializes a clipping rect for the header based on the margins of the header and the padding of the
 * recycler.
 * FIXME: Currently right margin in VERTICAL orientation and bottom margin in HORIZONTAL
 * orientation are clipped so they look accurate, but the headers are not being drawn at the
 * correctly smaller width and height respectively.
 *
 * @param clipRect     {@link Rect} for clipping a provided header to the padding of a recycler view
 * @param recyclerView for which to provide a header
 * @param header       for clipping
 */
private void initClipRectForHeader(@NonNull Rect clipRect, @NonNull RecyclerView recyclerView, @NonNull View header) {
    mDimensionCalculator.initMargins(clipRect, header);
    if (mOrientationProvider.getOrientation(recyclerView) == LinearLayout.VERTICAL) {
        clipRect.set(
                recyclerView.getPaddingLeft(),
                recyclerView.getPaddingTop(),
                recyclerView.getWidth() - recyclerView.getPaddingRight() - clipRect.right,
                recyclerView.getHeight() - recyclerView.getPaddingBottom());
    } else {
        clipRect.set(
                recyclerView.getPaddingLeft(),
                recyclerView.getPaddingTop(),
                recyclerView.getWidth() - recyclerView.getPaddingRight(),
                recyclerView.getHeight() - recyclerView.getPaddingBottom() - clipRect.bottom);
    }
}
 
Example 2
Source File: PointIndicator.java    From IndicatorBox with MIT License 6 votes vote down vote up
/**
 * 添加单个指示器
 * @param backgroundResId
 * @param animator
 */
private void addIndicator(@DrawableRes int backgroundResId, Animator animator){
    if (animator.isRunning()){
        animator.end();
        animator.cancel();
    }
    View indicator = new View(getContext());
    indicator.setBackgroundResource(backgroundResId);
    addView(indicator, mIndicatorWidth, mIndicatorHeight);
    LayoutParams lp = (LayoutParams) indicator.getLayoutParams();
    if (mOrientation == LinearLayout.HORIZONTAL){
        lp.leftMargin = mIndicatorMargin;
        lp.rightMargin = mIndicatorMargin;
    }else if (mOrientation == LinearLayout.VERTICAL){
        lp.topMargin = mIndicatorMargin;
        lp.bottomMargin = mIndicatorMargin;
    }
    indicator.setLayoutParams(lp);
    animator.setTarget(indicator);
    animator.start();
}
 
Example 3
Source File: HeaderRenderer.java    From ZhiHu-TopAnswer with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes a clipping rect for the header based on the margins of the header and the padding of the
 * recycler.
 * FIXME: Currently right margin in VERTICAL orientation and bottom margin in HORIZONTAL
 * orientation are clipped so they look accurate, but the headers are not being drawn at the
 * correctly smaller width and height respectively.
 *
 * @param clipRect {@link Rect} for clipping a provided header to the padding of a recycler view
 * @param recyclerView for which to provide a header
 * @param header       for clipping
 */
private void initClipRectForHeader(Rect clipRect, RecyclerView recyclerView, View header) {
  mDimensionCalculator.initMargins(clipRect, header);
  if (mOrientationProvider.getOrientation(recyclerView) == LinearLayout.VERTICAL) {
    clipRect.set(
        recyclerView.getPaddingLeft(),
        recyclerView.getPaddingTop(),
        recyclerView.getWidth() - recyclerView.getPaddingRight() - clipRect.right,
        recyclerView.getHeight() - recyclerView.getPaddingBottom());
  } else {
      clipRect.set(
        recyclerView.getPaddingLeft(),
        recyclerView.getPaddingTop(),
        recyclerView.getWidth() - recyclerView.getPaddingRight(),
        recyclerView.getHeight() - recyclerView.getPaddingBottom() - clipRect.bottom);
  }
}
 
Example 4
Source File: CardLayoutManager.java    From CardLayoutManager with Apache License 2.0 6 votes vote down vote up
private void findTopView() {
    if ((mOrientation == LinearLayout.HORIZONTAL && Math.abs(mDx) > mMinDistance) ||
            (mOrientation == LinearLayout.VERTICAL && Math.abs(mDy) > mMinDistance)) {
        if (mAnimStatus == ANIMATION_IN) {
            if (mOnCardSwipeListener != null) {
                mOnCardSwipeListener.onAnimInStop(getViewByPosition(mTopPosition), mTopPosition);
            }
        } else if (mAnimStatus == ANIMATION_OUT) {
            if (mOnCardSwipeListener != null) {
                mOnCardSwipeListener.onAnimOutStop(getViewByPosition(mTopPosition), mTopPosition, mAnimDirection);
            }
        }
        mAnimStatus = NO_ANIMATION;
        mDx = 0;
        mDy = 0;
        mTopPosition++;
        mIsScrollEnabled = false;
        mIsSwipe = false;
        mCardSwipeController.setDegree(0);
    }
}
 
Example 5
Source File: HeaderRenderer.java    From UltimateRecyclerView with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a clipping rect for the header based on the margins of the header and the padding of the
 * recycler.
 * FIXME: Currently right margin in VERTICAL orientation and bottom margin in HORIZONTAL
 * orientation are clipped so they look accurate, but the headers are not being drawn at the
 * correctly smaller width and height respectively.
 *
 * @param recyclerView for which to provide a header
 * @param header       for clipping
 * @return a {@link Rect} for clipping a provided header to the padding of a recycler view
 */
private Rect getClipRectForHeader(RecyclerView recyclerView, View header) {
  Rect headerMargins = mDimensionCalculator.getMargins(header);
  if (mOrientationProvider.getOrientation(recyclerView) == LinearLayout.VERTICAL) {
    return new Rect(
        recyclerView.getPaddingLeft(),
        recyclerView.getPaddingTop(),
        recyclerView.getWidth() - recyclerView.getPaddingRight() - headerMargins.right,
        recyclerView.getHeight() - recyclerView.getPaddingBottom());
  } else {
    return new Rect(
        recyclerView.getPaddingLeft(),
        recyclerView.getPaddingTop(),
        recyclerView.getWidth() - recyclerView.getPaddingRight(),
        recyclerView.getHeight() - recyclerView.getPaddingBottom() - headerMargins.bottom);
  }
}
 
Example 6
Source File: DialerCallBar.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
public DialerCallBar(Context context, AttributeSet attrs, int style) {
    super(context, attrs);
    LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.dialpad_additional_buttons, this, true);
    findViewById(R.id.dialVideoButton).setOnClickListener(this);
    findViewById(R.id.dialButton).setOnClickListener(this);
    findViewById(R.id.deleteButton).setOnClickListener(this);
    findViewById(R.id.deleteButton).setOnLongClickListener(this);
    
    if(getOrientation() == LinearLayout.VERTICAL) {
        LayoutParams lp;
        for(int i=0; i < getChildCount(); i++) {
            lp = (LayoutParams) getChildAt(i).getLayoutParams();
            int w = lp.width;
            lp.width = lp.height;
            lp.height = w;
            lp.gravity = Gravity.CENTER_HORIZONTAL;
            // Added for clarity but not necessary
            getChildAt(i).setLayoutParams(lp);
            
        }
    }
}
 
Example 7
Source File: HeaderRenderer.java    From googlecalendar with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes a clipping rect for the header based on the margins of the header and the padding of the
 * recycler.
 * FIXME: Currently right margin in VERTICAL orientation and bottom margin in HORIZONTAL
 * orientation are clipped so they look accurate, but the headers are not being drawn at the
 * correctly smaller width and height respectively.
 *
 * @param clipRect {@link Rect} for clipping a provided header to the padding of a recycler view
 * @param recyclerView for which to provide a header
 * @param header       for clipping
 */
private void initClipRectForHeader(Rect clipRect, RecyclerView recyclerView, View header) {
  mDimensionCalculator.initMargins(clipRect, header);
  if (mOrientationProvider.getOrientation(recyclerView) == LinearLayout.VERTICAL) {
    clipRect.set(
        recyclerView.getPaddingLeft(),
        recyclerView.getPaddingTop(),
        recyclerView.getWidth() - recyclerView.getPaddingRight() - clipRect.right,
        recyclerView.getHeight() - recyclerView.getPaddingBottom());
  } else {
      clipRect.set(
        recyclerView.getPaddingLeft(),
        recyclerView.getPaddingTop(),
        recyclerView.getWidth() - recyclerView.getPaddingRight(),
        recyclerView.getHeight() - recyclerView.getPaddingBottom() - clipRect.bottom);
  }
}
 
Example 8
Source File: GalleryLayoutManager.java    From CardSlideView with Apache License 2.0 5 votes vote down vote up
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
    if (mOrientation == LinearLayout.VERTICAL) {
        return new LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
    } else {
        return new LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
    }
}
 
Example 9
Source File: GalleryLayoutManager.java    From CardSlideView with Apache License 2.0 5 votes vote down vote up
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
    if (mOrientation == LinearLayout.VERTICAL) {
        return 0;
    }
    if (getChildCount() == 0 || dx == 0) {
        return 0;
    }
    int offset = -dx;
    final OrientationHelper orientationHelper = getOrientationHelper();
    final int centerToStart = (orientationHelper.getEndAfterPadding() - orientationHelper.getStartAfterPadding()) / 2 + orientationHelper.getStartAfterPadding();
    View child;
    if (dx > 0) {
        child = getChildAt(getChildCount() - 1);
        if (child != null && getPosition(child) == getItemCount() - 1 && !isLooper) {
            // 计算全部加载完后item的偏移量,右边会留出空隙
            offset = -Math.max(0, Math.min(dx, (child.getRight() - child.getLeft()) / 2 + child.getLeft() - centerToStart));
        }
    } else {
        child = getChildAt(0);
        if (mFirstVisiblePosition == 0 && child != null && !isLooper) {
            // 计算首次加载item的偏移量,左边会留出空隙
            offset = -Math.min(0, Math.max(dx, ((child.getRight() - child.getLeft()) / 2 + child.getLeft()) - centerToStart));
        }
    }
    // 记录偏移量
    getState().scrollOffset = -offset;
    fill(recycler, -offset);
    offsetChildrenHorizontal(offset);
    return -offset;
}
 
Example 10
Source File: DragLinearLayout.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public void setOrientation(int orientation){
    if(LinearLayout.VERTICAL == orientation){
        throw new IllegalArgumentException("DragLinearLayout must be HORIZONTAL.");
    }
    super.setOrientation(orientation);
}
 
Example 11
Source File: HeaderPositionCalculator.java    From toktok-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Determines if a view should have a sticky header.
 * The view has a sticky header if:
 * 1. It is the first element in the recycler view
 * 2. It has a valid ID associated to its position
 *
 * @param itemView    given by the RecyclerView
 * @param orientation of the Recyclerview
 * @param position    of the list item in question
 * @return True if the view should have a sticky header
 */
public boolean hasStickyHeader(@NonNull View itemView, int orientation, int position) {
    int offset, margin;
    mDimensionCalculator.initMargins(mTempRect1, itemView);
    if (orientation == LinearLayout.VERTICAL) {
        offset = itemView.getTop();
        margin = mTempRect1.top;
    } else {
        offset = itemView.getLeft();
        margin = mTempRect1.left;
    }

    return offset <= margin && mAdapter.getHeaderId(position) >= 0;
}
 
Example 12
Source File: PullToRefreshBase.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void setOrientation(int orientation) {
    if (LinearLayout.VERTICAL != orientation) {
        throw new IllegalArgumentException(
                "This class only supports VERTICAL orientation.");
    }

    // Only support vertical orientation
    super.setOrientation(orientation);
}
 
Example 13
Source File: HeaderPositionCalculator.java    From IndexRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if a view should have a sticky header.
 * The view has a sticky header if:
 * 1. It is the first element in the recycler view
 * 2. It has a valid ID associated to its position
 *
 * @param itemView given by the RecyclerView
 * @param orientation of the Recyclerview
 * @param position of the list item in question
 * @return True if the view should have a sticky header
 */
public boolean hasStickyHeader(View itemView, int orientation, int position) {
  int offset, margin;
  mDimensionCalculator.initMargins(mTempRect1, itemView);
  if (orientation == LinearLayout.VERTICAL) {
    offset = itemView.getTop();
    margin = mTempRect1.top;
  } else {
    offset = itemView.getLeft();
    margin = mTempRect1.left;
  }

  return offset <= margin && mAdapter.getHeaderId(position) >= 0;
}
 
Example 14
Source File: HeaderPositionCalculator.java    From sticky-headers-recyclerview with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if a view should have a sticky header.
 * The view has a sticky header if:
 * 1. It is the first element in the recycler view
 * 2. It has a valid ID associated to its position
 *
 * @param itemView given by the RecyclerView
 * @param orientation of the Recyclerview
 * @param position of the list item in question
 * @return True if the view should have a sticky header
 */
public boolean hasStickyHeader(View itemView, int orientation, int position) {
  int offset, margin;
  mDimensionCalculator.initMargins(mTempRect1, itemView);
  if (orientation == LinearLayout.VERTICAL) {
    offset = itemView.getTop();
    margin = mTempRect1.top;
  } else {
    offset = itemView.getLeft();
    margin = mTempRect1.left;
  }

  return offset <= margin && mAdapter.getHeaderId(position) >= 0;
}
 
Example 15
Source File: TitanAdapter.java    From TitanRecyclerView with MIT License 5 votes vote down vote up
public void setFooterView(View footerView, int orientation) {
    if (null == footerView.getLayoutParams()) {
        if (LinearLayout.VERTICAL == orientation) {
            footerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        } else {
            footerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        }
    }
    this.mFooterView = footerView;
    this.mHasFooter = true;
}
 
Example 16
Source File: GalleryLayoutManager.java    From CardSlideView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canScrollVertically() {
    return mOrientation == LinearLayout.VERTICAL;
}
 
Example 17
Source File: IncDecImageButton.java    From IncDec with Apache License 2.0 4 votes vote down vote up
private void setupConfiguration(int orientation, String type) {
    if(orientation==LinearLayout.VERTICAL)
        setLayoutParams(0,LinearLayout.LayoutParams.WRAP_CONTENT);
    else
        setLayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,0);

    fixOrientation(layout,orientation);

    if(type.equals(TYPE_ARRAY)){

    }else if(type.equals(TYPE_FLOAT)){

    }else{

    }
}
 
Example 18
Source File: ExpandableLinearLayout.java    From ExpandableLayout with Apache License 2.0 4 votes vote down vote up
private boolean isVertical() {
    return getOrientation() == LinearLayout.VERTICAL;
}
 
Example 19
Source File: TopRightWeightedLayout.java    From Camera2 with Apache License 2.0 4 votes vote down vote up
/**
 * Swap gravity:
 * left for bottom
 * right for top
 * center horizontal for center vertical
 * etc
 * <p>
 * also swap left|right padding for bottom|top
 */
private void fixGravityAndPadding(int direction)
{
    for (int i = 0; i < getChildCount(); i++)
    {
        // gravity swap
        View v = getChildAt(i);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) v.getLayoutParams();
        int gravity = layoutParams.gravity;

        if (direction == LinearLayout.VERTICAL)
        {
            if ((gravity & Gravity.LEFT) != 0)
            {   // if gravity left is set . . .
                gravity &= ~Gravity.LEFT;          // unset left
                gravity |= Gravity.BOTTOM;         // and set bottom
            }
        } else
        {
            if ((gravity & Gravity.BOTTOM) != 0)
            { // etc
                gravity &= ~Gravity.BOTTOM;
                gravity |= Gravity.LEFT;
            }
        }

        if (direction == LinearLayout.VERTICAL)
        {
            if ((gravity & Gravity.RIGHT) != 0)
            {
                gravity &= ~Gravity.RIGHT;
                gravity |= Gravity.TOP;
            }
        } else
        {
            if ((gravity & Gravity.TOP) != 0)
            {
                gravity &= ~Gravity.TOP;
                gravity |= Gravity.RIGHT;
            }
        }

        // don't mess with children that are centered in both directions
        if ((gravity & Gravity.CENTER) != Gravity.CENTER)
        {
            if (direction == LinearLayout.VERTICAL)
            {
                if ((gravity & Gravity.CENTER_VERTICAL) != 0)
                {
                    gravity &= ~Gravity.CENTER_VERTICAL;
                    gravity |= Gravity.CENTER_HORIZONTAL;
                }
            } else
            {
                if ((gravity & Gravity.CENTER_HORIZONTAL) != 0)
                {
                    gravity &= ~Gravity.CENTER_HORIZONTAL;
                    gravity |= Gravity.CENTER_VERTICAL;
                }
            }
        }

        layoutParams.gravity = gravity;

        // padding swap
        int paddingLeft = v.getPaddingLeft();
        int paddingTop = v.getPaddingTop();
        int paddingRight = v.getPaddingRight();
        int paddingBottom = v.getPaddingBottom();
        v.setPadding(paddingBottom, paddingRight, paddingTop, paddingLeft);
    }
}
 
Example 20
Source File: BootstrapButtonGroupExample.java    From Android-Bootstrap with MIT License 4 votes vote down vote up
@OnClick(R.id.bbutton_group_orientation_change_btn) void onOrientationChangeExampleClicked() {
    boolean isHorizontal = orientationChange.getOrientation() == LinearLayout.HORIZONTAL;
    int newOrientation = isHorizontal ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL;
    orientationChange.setOrientation(newOrientation);
}