Java Code Examples for android.widget.ScrollView#getChildAt()

The following examples show how to use android.widget.ScrollView#getChildAt() . 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: CapturePictureUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 通过 ScrollView 绘制为 Bitmap
 * <pre>
 *     ScrollView 容器中不能有诸如 ListView、GridView、WebView 这样的高度可变的控件
 * </pre>
 * @param scrollView {@link ScrollView}
 * @param config     {@link Bitmap.Config}
 * @return {@link Bitmap}
 */
public static Bitmap snapshotByScrollView(final ScrollView scrollView, final Bitmap.Config config) {
    if (scrollView == null || config == null) return null;
    try {
        View view = scrollView.getChildAt(0);
        int width = view.getWidth();
        int height = view.getHeight();

        Bitmap bitmap = Bitmap.createBitmap(width, height, config);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawColor(BACKGROUND_COLOR);
        scrollView.layout(0, 0, scrollView.getMeasuredWidth(),
                scrollView.getMeasuredHeight());
        scrollView.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "snapshotByScrollView");
    }
    return null;
}
 
Example 2
Source File: Utils.java    From MaterialViewPager with Apache License 2.0 6 votes vote down vote up
static boolean canScroll(View view) {
    if (view instanceof ScrollView) {
        ScrollView scrollView = (ScrollView) view;
        View child = scrollView.getChildAt(0);
        if (child != null) {
            int childHeight = child.getHeight();
            return scrollView.getHeight() < childHeight + scrollView.getPaddingTop() + scrollView.getPaddingBottom();
        }
        return false;
    } else if (view instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) view;
        int yOffset = recyclerView.computeVerticalScrollOffset();
        return yOffset != 0;
    }
    return true;
}
 
Example 3
Source File: BoardAdapter.java    From BoardView with Apache License 2.0 5 votes vote down vote up
public void removeItem(int column, int index){
    BoardItem item = (BoardItem)((ViewGroup)((ViewGroup)boardView.getChildAt(0)).getChildAt(0)).getChildAt(column);
    ScrollView scrollView = (ScrollView)item.getChildAt(1);
    LinearLayout llColumn = (LinearLayout)scrollView.getChildAt(0);
    llColumn.removeViewAt(index);
    llColumn.invalidate();
    columns.get(column).objects.remove(index);
    columns.get(column).views.remove(index);
}
 
Example 4
Source File: BoardAdapter.java    From BoardView with Apache License 2.0 5 votes vote down vote up
public void addItem(int column,int index, Object item){
    BoardItem boardItem = (BoardItem)((ViewGroup)((ViewGroup)boardView.getChildAt(0)).getChildAt(0)).getChildAt(column);
    TransitionManager.beginDelayedTransition(boardItem, transition);
    ScrollView scrollView = (ScrollView)boardItem.getChildAt(1);
    LinearLayout llColumn = (LinearLayout)scrollView.getChildAt(0);
    columns.get(column).objects.add(index,item);
    View v = createItemView(context,columns.get(column).header_object,item,column,index);
    llColumn.addView(v,index);
    boardView.addBoardItem(v,column);
    llColumn.invalidate();
    columns.get(column).views.add(index,v);
}
 
Example 5
Source File: NoteEditActivity.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void handleIniCursor() {
	super.handleIniCursor();
	noteEditTitle.setText(Title);
	editTextWrapper.forceRefocus();
	if(content!=null){
		editTextWrapper.setHtml(content);
	}
	RichEdit richEdit  = null;
	ViewGroup realEditor =(ViewGroup) editTextWrapper.getChildAt(0);
	int wrapperChildNum = realEditor.getChildCount();
	for(int i = 0;i<wrapperChildNum;i++){
		View v  = realEditor.getChildAt(i);
		if(v instanceof ScrollView){
			ScrollView editWrapper = (ScrollView)v;
			int editChildIndex = editWrapper.getChildCount();
			for(int childIndex = 0;childIndex <editChildIndex;childIndex++){
				if(editWrapper.getChildAt(childIndex )  instanceof  RichEdit){
					richEdit = (RichEdit)editWrapper.getChildAt(childIndex );
				}
			}
		}
	}
	if(viewIndex>-1){
		View richTxt = richEdit.getChildAt(viewIndex);
		richTxt.requestFocus();
		if(sel>-1 && richTxt instanceof RichEditText){
			((RichEditText)richTxt).editText.setSelection(sel);
		}
	}
}
 
Example 6
Source File: ParallaxViewController.java    From Carpaccio with Apache License 2.0 5 votes vote down vote up
public void registerParallax(ScrollView view, boolean replaceWithObservableScrollView) {
    if (replaceWithObservableScrollView && !(view instanceof ObservableScrollView)) {
        CommonViewController replaceViewController = new CommonViewController();
        ObservableScrollView newView = replaceViewController.replaceViewithTagToRemove(view, "com.github.ksoichiro.android.observablescrollview.ObservableScrollView", "registerParallax()");

        if (view.getChildCount() > 0) {
            View scrollViewChild = view.getChildAt(0);
            view.removeView(scrollViewChild);
            newView.addView(scrollViewChild);
        }

        view = newView;
    }

    if (view != null)
        ((ObservableScrollView) view).setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
            @Override
            public void onScrollChanged(int i, boolean b, boolean b1) {
                scrolled(i);
            }

            @Override
            public void onDownMotionEvent() {

            }

            @Override
            public void onUpOrCancelMotionEvent(ScrollState scrollState) {

            }
        });
}
 
Example 7
Source File: BounceTouchListener.java    From Bounce with Apache License 2.0 5 votes vote down vote up
private boolean hasHitBottom() {
    if (mMainView instanceof ScrollView) {
        ScrollView scrollView = (ScrollView) mMainView;
        View view = scrollView.getChildAt(scrollView.getChildCount() - 1);
        int diff = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));// Calculate the scrolldiff
        return diff == 0;
    } else if (mMainView instanceof ListView) {
        ListView listView = (ListView) mMainView;
        if (listView.getAdapter() != null) {
            if (listView.getAdapter().getCount() > 0) {
                return listView.getLastVisiblePosition() == listView.getAdapter().getCount() - 1 &&
                        listView.getChildAt(listView.getChildCount() - 1).getBottom() <= listView.getHeight();
            }
        }
    } else if (mMainView instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) mMainView;
        if (recyclerView.getAdapter() != null && recyclerView.getLayoutManager() != null) {
            RecyclerView.Adapter adapter = recyclerView.getAdapter();
            if (adapter.getItemCount() > 0) {
                RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                if (layoutManager instanceof LinearLayoutManager) {
                    LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
                    return linearLayoutManager.findLastCompletelyVisibleItemPosition() == adapter.getItemCount() - 1;
                } else if (layoutManager instanceof StaggeredGridLayoutManager) {
                    StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
                    int[] checks = staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(null);
                    for (int check : checks) {
                        if (check == adapter.getItemCount() - 1)
                            return true;
                    }
                }
            }
        }
    }
    return false;
}