Search in sources :

Example 26 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project TwinklingRefreshLayout by lcodecorex.

the class ScrollingUtil method isRecyclerViewToTop.

public static boolean isRecyclerViewToTop(RecyclerView recyclerView) {
    if (recyclerView != null) {
        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
        if (manager == null) {
            return true;
        }
        if (manager.getItemCount() == 0) {
            return true;
        }
        if (manager instanceof LinearLayoutManager) {
            LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
            int firstChildTop = 0;
            if (recyclerView.getChildCount() > 0) {
                // 处理item高度超过一屏幕时的情况
                View firstVisibleChild = recyclerView.getChildAt(0);
                if (firstVisibleChild != null && firstVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) {
                    if (android.os.Build.VERSION.SDK_INT < 14) {
                        return !(ViewCompat.canScrollVertically(recyclerView, -1) || recyclerView.getScrollY() > 0);
                    } else {
                        return !ViewCompat.canScrollVertically(recyclerView, -1);
                    }
                }
                // 如果RecyclerView的子控件数量不为0,获取第一个子控件的top
                // 解决item的topMargin不为0时不能触发下拉刷新
                View firstChild = recyclerView.getChildAt(0);
                RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) firstChild.getLayoutParams();
                firstChildTop = firstChild.getTop() - layoutParams.topMargin - getRecyclerViewItemTopInset(layoutParams) - recyclerView.getPaddingTop();
            }
            if (layoutManager.findFirstCompletelyVisibleItemPosition() < 1 && firstChildTop == 0) {
                return true;
            }
        } else if (manager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;
            int[] out = layoutManager.findFirstCompletelyVisibleItemPositions(null);
            if (out[0] < 1) {
                return true;
            }
        }
    }
    return false;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) GridView(android.widget.GridView) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) View(android.view.View) ListView(android.widget.ListView) WebView(android.webkit.WebView)

Example 27 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project twoway-view by lucasr.

the class BaseLayoutManager method generateLayoutParams.

@Override
public LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
    final LayoutParams lanedLp = new LayoutParams((MarginLayoutParams) lp);
    if (isVertical()) {
        lanedLp.width = LayoutParams.MATCH_PARENT;
        lanedLp.height = lp.height;
    } else {
        lanedLp.width = lp.width;
        lanedLp.height = LayoutParams.MATCH_PARENT;
    }
    return lanedLp;
}
Also used : LayoutParams(android.support.v7.widget.RecyclerView.LayoutParams) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams)

Example 28 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project material-components-android by material-components.

the class CoordinatorSnackbarWithFabTest method testBehaviorBasedSlidingFromRuntimeApiCall.

@Test
public void testBehaviorBasedSlidingFromRuntimeApiCall() {
    // Use a layout in which an AppCompatTextView child doesn't have any configured Behavior
    onView(withId(R.id.coordinator_stub)).perform(inflateViewStub(R.layout.design_snackbar_behavior_runtime));
    // and configure that Behavior at runtime by setting it on its LayoutParams
    final AppCompatTextView textView = (AppCompatTextView) mCoordinatorLayout.findViewById(R.id.text);
    final CoordinatorLayout.LayoutParams textViewLp = (CoordinatorLayout.LayoutParams) textView.getLayoutParams();
    textViewLp.setBehavior(new TestFloatingBehavior());
    // Create and show a snackbar
    mSnackbar = Snackbar.make(mCoordinatorLayout, MESSAGE_TEXT, Snackbar.LENGTH_INDEFINITE).setAction(ACTION_TEXT, mock(View.OnClickListener.class));
    SnackbarUtils.showTransientBottomBarAndWaitUntilFullyShown(mSnackbar);
    verifySnackbarViewStacking(textView, 0);
}
Also used : AppCompatTextView(android.support.v7.widget.AppCompatTextView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View) TestFloatingBehavior(android.support.design.testapp.custom.TestFloatingBehavior) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 29 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project BGARefreshLayout-Android by bingoogolapple.

the class Divider method drawVertical.

public void drawVertical(Canvas c, RecyclerView parent) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();
    View child;
    RecyclerView.LayoutParams layoutParams;
    int top;
    int bottom;
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++) {
        child = parent.getChildAt(i);
        layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
        top = child.getBottom() + layoutParams.bottomMargin;
        bottom = top + mDividerDrawable.getIntrinsicHeight();
        mDividerDrawable.setBounds(left, top, right, bottom);
        mDividerDrawable.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 30 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project smooth-app-bar-layout by henrytao-me.

the class SmoothAppBarLayout method onLayout.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);
    int i = 0;
    for (int z = this.getChildCount(); i < z; ++i) {
        View child = this.getChildAt(i);
        LayoutParams childLp = (LayoutParams) child.getLayoutParams();
        Interpolator interpolator = childLp.getScrollInterpolator();
        if (interpolator != null) {
            mHaveChildWithInterpolator = true;
            break;
        }
    }
}
Also used : Interpolator(android.view.animation.Interpolator) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

View (android.view.View)77 RecyclerView (android.support.v7.widget.RecyclerView)67 ViewGroup (android.view.ViewGroup)21 TextView (android.widget.TextView)21 ImageView (android.widget.ImageView)13 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)12 Toolbar (android.support.v7.widget.Toolbar)9 FrameLayout (android.widget.FrameLayout)9 Rect (android.graphics.Rect)8 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)8 BindView (butterknife.BindView)8 ActionMenuView (android.support.v7.widget.ActionMenuView)7 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)6 LinearLayout (android.widget.LinearLayout)6 CollapsibleActionView (android.support.v7.view.CollapsibleActionView)5 MenuView (android.support.v7.view.menu.MenuView)5 EditText (android.widget.EditText)5 ImageView (carbon.widget.ImageView)5 TextView (carbon.widget.TextView)5 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)5