Java Code Examples for android.widget.LinearLayout#HORIZONTAL

The following examples show how to use android.widget.LinearLayout#HORIZONTAL . 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: LocalOfficeActivity.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
private void initRecyclerView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    final RecycleViewItemLine line = new RecycleViewItemLine(this, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new LocalOfficeAdapter(this);
    recyclerView.setAdapter(adapter);
    recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            SwipeRefreshLayout swipeToRefresh = recyclerView.getSwipeToRefresh();
            if (swipeToRefresh.isRefreshing()) {
                recyclerView.setRefreshing(false);
            }else {
                initData();
            }
        }
    });
}
 
Example 2
Source File: ReboundLayout.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    float progress = ((endProgress - startProgress) * interpolatedTime) + startProgress;
    Log.i(TAG, "applyTransformation: interpolatedTime =" + interpolatedTime);
    if (mOrientation == LinearLayout.HORIZONTAL) {
        scrollBy((int) ((MAX_WIDTH - getScrollX()) * progress), 0);
    } else {

        float v = (MAX_WIDTH - getScrollY()) * progress;
        Log.i(TAG, "applyTransformation: getScrollY() =" + getScrollY() + " progress = " + progress + " v =" + v);
        scrollBy(0, (int) v);
    }

    if (progress >= 1) {
        isRunAnim = false;
    }
}
 
Example 3
Source File: GalleryLayoutManager.java    From CardSlideView with Apache License 2.0 6 votes vote down vote up
private void fill(RecyclerView.Recycler recycler, int scrollOffset) {
    if (getItemCount() == 0) {
        return;
    }
    if (mOrientation == LinearLayout.HORIZONTAL) {
        fillWithHorizontal(recycler, scrollOffset);
    } else {
        fillWithVertical(recycler, scrollOffset);
    }
    if (mPageTransformer != null) {
        View child;
        for (int i = 0; i < getChildCount(); i++) {
            child = getChildAt(i);
            if (child == null) {
                continue;
            }
            mPageTransformer.transformPage(child, calculateOffsetPercentToCenter(child, scrollOffset), mOrientation);
        }
    }
}
 
Example 4
Source File: SegmentedGroup.java    From SSForms with GNU General Public License v3.0 6 votes vote down vote up
public void updateBackground() {
    mDrawableMap = new HashMap<>();
    int count = super.getChildCount();
    for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        updateBackground(child);

        // If this is the last view, don't set LayoutParams
        if (i == count - 1) break;

        LayoutParams initParams = (LayoutParams) child.getLayoutParams();
        LayoutParams params = new LayoutParams(initParams.width, initParams.height, initParams.weight);
        // Check orientation for proper margins
        if (getOrientation() == LinearLayout.HORIZONTAL) {
            params.setMargins(0, 0, -mMarginDp, 0);
        } else {
            params.setMargins(0, 0, 0, -mMarginDp);
        }
        child.setLayoutParams(params);
    }
}
 
Example 5
Source File: TopRightWeightedLayout.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
/**
 * Set the orientation of this layout if it has changed,
 * and center the elements based on the new orientation.
 */
private void checkOrientation(int orientation)
{
    final boolean isHorizontal = LinearLayout.HORIZONTAL == getOrientation();
    final boolean isPortrait = Configuration.ORIENTATION_PORTRAIT == orientation;
    if (isPortrait && !isHorizontal)
    {
        // Portrait orientation is out of sync, setting to horizontal
        // and reversing children
        fixGravityAndPadding(LinearLayout.HORIZONTAL);
        setOrientation(LinearLayout.HORIZONTAL);
        reverseChildren();
        requestLayout();
    } else if (!isPortrait && isHorizontal)
    {
        // Landscape orientation is out of sync, setting to vertical
        // and reversing children
        fixGravityAndPadding(LinearLayout.VERTICAL);
        setOrientation(LinearLayout.VERTICAL);
        reverseChildren();
        requestLayout();
    }
}
 
Example 6
Source File: ReboundLayout.java    From CoordinatorLayoutExample with Apache License 2.0 5 votes vote down vote up
@Override
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) {
    // 如果在自定义ViewGroup之上还有父View交给我来处理
    getParent().requestDisallowInterceptTouchEvent(true);
    int orientation = getOrientation();
    if (orientation == LinearLayout.HORIZONTAL) {
        handleHorizontal(target, dx, consumed);
    } else {
        handleVertical(target, dy, consumed);
    }

}
 
Example 7
Source File: ExpandableLayout.java    From ExpandableLayout with Apache License 2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int width = getMeasuredWidth();
    int height = getMeasuredHeight();

    int size = orientation == LinearLayout.HORIZONTAL ? width : height;

    setVisibility(expansion == 0 && size == 0 ? GONE : VISIBLE);

    int expansionDelta = size - Math.round(size * expansion);
    if (parallax > 0) {
        float parallaxDelta = expansionDelta * parallax;
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            if (orientation == HORIZONTAL) {
                int direction = -1;
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 && getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
                    direction = 1;
                }
                child.setTranslationX(direction * parallaxDelta);
            } else {
                child.setTranslationY(-parallaxDelta);
            }
        }
    }

    if (orientation == HORIZONTAL) {
        setMeasuredDimension(width - expansionDelta, height);
    } else {
        setMeasuredDimension(width, height - expansionDelta);
    }
}
 
Example 8
Source File: GalleryLayoutManager.java    From CardSlideView with Apache License 2.0 5 votes vote down vote up
/**
 * @param child  计算的view
 * @param offset view的滑动偏移量
 * @return 返回view距离中心轴的距离
 */
private int calculateDistanceToCenter(View child, float offset) {
    final OrientationHelper orientationHelper = getOrientationHelper();
    final int centerToStart = (orientationHelper.getEndAfterPadding() - orientationHelper.getStartAfterPadding()) / 2 + orientationHelper.getStartAfterPadding();
    if (mOrientation == LinearLayout.HORIZONTAL) {
        return (int) (child.getWidth() / 2 - offset + child.getLeft() - centerToStart);
    } else {
        return (int) (child.getHeight() / 2 - offset + child.getTop() - centerToStart);
    }
}
 
Example 9
Source File: PagerIndicator.java    From oneHookLibraryAndroid with Apache License 2.0 5 votes vote down vote up
private LinearLayout.LayoutParams obtainLayoutParams() {
    final int size = mDotSize;
    final int margin = mDotMargin;
    final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(size, size);
    if (getOrientation() == LinearLayout.HORIZONTAL) {
        lp.gravity = Gravity.CENTER_VERTICAL;
        lp.leftMargin = margin;
        lp.rightMargin = margin;
    } else {
        lp.gravity = Gravity.CENTER_HORIZONTAL;
        lp.topMargin = margin;
        lp.bottomMargin = margin;
    }
    return lp;
}
 
Example 10
Source File: GalleryLayoutManager.java    From CardSlideView with Apache License 2.0 5 votes vote down vote up
private OrientationHelper getOrientationHelper() {
    if (mOrientation == LinearLayout.HORIZONTAL) {
        if (mHorizontalHelper == null) {
            mHorizontalHelper = OrientationHelper.createHorizontalHelper(this);
        }
        return mHorizontalHelper;
    } else {
        if (mVerticalHelper == null) {
            mVerticalHelper = OrientationHelper.createVerticalHelper(this);
        }
        return mVerticalHelper;
    }
}
 
Example 11
Source File: ExpandableTextView.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void setOrientation(int orientation) {
    if (LinearLayout.HORIZONTAL == orientation) {
        throw new IllegalArgumentException("ExpandableTextView only supports Vertical Orientation.");
    }
    super.setOrientation(orientation);
}
 
Example 12
Source File: ExpandableTextView.java    From ExpandableTextView with Apache License 2.0 5 votes vote down vote up
@Override
public void setOrientation(int orientation) {
    if (LinearLayout.HORIZONTAL == orientation) {
        throw new IllegalArgumentException("ExpandableTextView only supports Vertical Orientation.");
    }
    super.setOrientation(orientation);
}
 
Example 13
Source File: ExpandableTextView.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
@Override
public void setOrientation(int orientation) {
    if (LinearLayout.HORIZONTAL == orientation) {
        throw new IllegalArgumentException("ExpandableTextView only supports Vertical Orientation.");
    }
    super.setOrientation(orientation);
}
 
Example 14
Source File: DetailVideoActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
private void initYCRefreshView() {
    linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);
    final RecycleViewItemLine line = new RecycleViewItemLine(this, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new DetailVideoAdapter(this);
    recyclerView.setAdapter(adapter);
    recyclerView.setRefreshing(false);
    recyclerView.scrollTo(0,0);
    recyclerView.scrollBy(0,0);
    addHeader();
}
 
Example 15
Source File: CardLayoutManager.java    From CardLayoutManager with Apache License 2.0 5 votes vote down vote up
private int getMinDistance() {
    if (mOrientation == LinearLayout.HORIZONTAL) {
        return getWidth() - getPaddingLeft() - getPaddingRight();
    } else {
        return getHeight() - getPaddingTop() - getPaddingBottom();
    }
}
 
Example 16
Source File: BaseCardSwipeController.java    From CardLayoutManager with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canSwipeOut(View view, int position, int dx, int dy, int velocityX, int velocityY) {
    int width = view.getWidth();
    int height = view.getHeight();
    boolean isOverBounds = mOrientation == LinearLayout.HORIZONTAL ? Math.abs(dx) >= width / 2 : Math.abs(dy) >= height / 2;
    return isOverBounds || exceed(velocityX, velocityY);
}
 
Example 17
Source File: GalleryLayoutManager.java    From CardSlideView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canScrollHorizontally() {
    return mOrientation == LinearLayout.HORIZONTAL;
}
 
Example 18
Source File: HeaderFooterActivity.java    From YCRefreshView with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_refresh_view);
    recyclerView = findViewById(R.id.recyclerView);
    adapter = new PersonAdapter(this);
    recyclerView.setAdapter(adapter);

    final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);
    DividerViewItemLine itemDecoration = new DividerViewItemLine(
            this.getResources().getColor(R.color.color_f9f9f9),
            LibUtils.dip2px(this,0.5f),
            LibUtils.dip2px(this,72),0);
    itemDecoration.setDrawLastItem(true);
    itemDecoration.setDrawHeaderFooter(true);
    recyclerView.addItemDecoration(itemDecoration);

    final RecycleViewItemLine line = new RecycleViewItemLine(this,
            LinearLayout.HORIZONTAL, 1, getResources().getColor(R.color.colorAccent));
    recyclerView.addItemDecoration(line);

    recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            recyclerView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    adapter.clear();
                    adapter.addAll(DataProvider.getPersonList(0));
                }
            },1500);
        }
    });
    //recyclerView.setRefreshing(true);
    recyclerView.setRefreshingColorResources(R.color.colorAccent);
    initHeader();
    adapter.addAll(DataProvider.getPersonList(0));
    adapter.setOnItemChildClickListener(new OnItemChildClickListener() {
        @Override
        public void onItemChildClick(View view, int position) {
            switch (view.getId()){
                case R.id.iv_news_image:
                    Toast.makeText(HeaderFooterActivity.this,
                            "点击图片了",Toast.LENGTH_SHORT).show();
                    break;
                case R.id.tv_title:
                    Toast.makeText(HeaderFooterActivity.this,
                            "点击标题",Toast.LENGTH_SHORT).show();
                    break;
                default:
                    break;
            }
        }
    });
}
 
Example 19
Source File: NormalRecyclerViewActivity.java    From YCRefreshView with Apache License 2.0 4 votes vote down vote up
private void initRecyclerView() {
    recyclerView = findViewById(R.id.recyclerView);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);


    final RecycleViewItemLine line = new RecycleViewItemLine(this, LinearLayout.HORIZONTAL,
            (int)AppUtils.convertDpToPixel(1,this),
            this.getResources().getColor(R.color.color_f9f9f9));
    recyclerView.addItemDecoration(line);
    adapter = new PersonAdapter(this);
    recyclerView.setAdapter(adapter);
    adapter.setMore(R.layout.view_more, new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    //刷新
                    if (!hasNetWork) {
                        adapter.pauseMore();
                        return;
                    }
                    adapter.addAll(DataProvider.getPersonList(page));
                    page++;
                }
            }, 2000);
        }
    });
    adapter.setNoMore(R.layout.view_nomore, new OnNoMoreListener() {
        @Override
        public void onNoMoreShow() {
            adapter.pauseMore();
        }

        @Override
        public void onNoMoreClick() {

        }
    });
    adapter.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(int position) {
            adapter.remove(position);
            return true;
        }
    });
    adapter.setError(R.layout.view_error, new OnErrorListener() {
        @Override
        public void onErrorShow() {
            adapter.resumeMore();
        }

        @Override
        public void onErrorClick() {
            adapter.resumeMore();
        }
    });
}
 
Example 20
Source File: RefreshAndMoreActivity2.java    From YCRefreshView with Apache License 2.0 4 votes vote down vote up
private void initView() {
    top = findViewById(R.id.top);
    recyclerView = findViewById(R.id.recyclerView);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);


    final RecycleViewItemLine line = new RecycleViewItemLine(this, LinearLayout.HORIZONTAL,
            (int)AppUtils.convertDpToPixel(1,this),
            this.getResources().getColor(R.color.color_666666));
    recyclerView.addItemDecoration(line);

    recyclerView.setAdapterWithProgress(adapter = new RecyclerArrayAdapter<PersonData>(this) {
        @Override
        public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
            return new PersonViewHolder(parent);
        }
    });
    adapter.setMore(R.layout.view_more2, new OnMoreListener() {
        @Override
        public void onMoreShow() {
            //不做处理
        }

        @Override
        public void onMoreClick() {
            //点击触发加载下一页数据
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    //刷新
                    if (!hasNetWork) {
                        adapter.pauseMore();
                        return;
                    }
                    adapter.addAll(DataProvider.getPersonList(10));
                    page++;
                }
            }, 200);
        }
    });


    adapter.setNoMore(R.layout.view_nomore, new OnNoMoreListener() {
        @Override
        public void onNoMoreShow() {
            adapter.pauseMore();
        }

        @Override
        public void onNoMoreClick() {
            Log.e("逗比","没有更多数据了");
        }
    });
    adapter.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(int position) {
            adapter.remove(position);
            return true;
        }
    });
    adapter.setError(R.layout.view_error, new OnErrorListener() {
        @Override
        public void onErrorShow() {
            adapter.resumeMore();
        }

        @Override
        public void onErrorClick() {
            adapter.resumeMore();
        }
    });
}