android.view.ViewGroup#setBottom ( )源码实例Demo

下面列出了android.view.ViewGroup#setBottom ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
public void testIsScrollableViewLargeEnoughToScrollWhenFalse() {
    final Context context = RuntimeEnvironment.application;
    final Pair<Integer, ViewGroup> heightsResult = prepareViewGroupWithValidChildHeights();

    final ViewGroup rootView = new FrameLayout(context);
    rootView.setBottom(heightsResult.first);

    final ViewGroup appBarLayout = new FrameLayout(context);
    final ViewGroup scrollableView = heightsResult.second;

    rootView.addView(appBarLayout);
    rootView.addView(scrollableView);

    assertFalse(ViewUtils.isScrollableViewLargeEnoughToScroll(rootView,
            appBarLayout,
            scrollableView,
            0));
}
 
@Test
public void testIsScrollableViewLargeEnoughToScrollWhenTrue() {
    final Context context = RuntimeEnvironment.application;
    final Pair<Integer, ViewGroup> heightsResult = prepareViewGroupWithValidChildHeights();

    final ViewGroup rootView = new FrameLayout(context);
    rootView.setBottom(heightsResult.first / 2);

    final ViewGroup appBarLayout = new FrameLayout(context);
    appBarLayout.setBottom(heightsResult.first / 2);

    final ViewGroup scrollableView = heightsResult.second;

    rootView.addView(appBarLayout);
    rootView.addView(scrollableView);

    assertTrue(ViewUtils.isScrollableViewLargeEnoughToScroll(rootView,
            appBarLayout,
            scrollableView,
            0));
}
 
private Pair<Integer, ViewGroup> prepareViewGroupWithValidChildHeights() {
    final Context context = RuntimeEnvironment.application;
    final int v1h = 101;
    final int v2h = 102;
    final int v3h = 103;
    final int v4h = 0;

    final ViewGroup vg = new FrameLayout(context);
    vg.setBottom(666);

    final View v1 = new View(context);
    v1.setBottom(v1h);
    vg.addView(v1);

    final View v2 = new View(context);
    v2.setBottom(v2h);
    vg.addView(v2);

    final View v3 = new View(context);
    v3.setBottom(v3h);
    vg.addView(v3);

    final View v4 = new View(context);
    v4.setBottom(v4h);
    vg.addView(v4);

    return new Pair<>(v1h + v2h + v3h + v4h, vg);
}
 
@Test
public void testChildHeightsEmptyViewGroup() {
    final ViewGroup vg = new FrameLayout(RuntimeEnvironment.application);
    vg.setBottom(666);

    assertEquals(0, ViewUtils.childHeights(vg));
}
 
 方法所在类