Android Utililty Methods View Set

List of utility methods to do View Set

Description

The list of methods to do View Set are organized into topic(s).

Method

voiddoAfterLayout(final View view, final Runnable runnable)
Runs a piece of code after the next layout run
final OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {
    @SuppressWarnings("deprecation")
    @Override
    public void onGlobalLayout() {
        view.getViewTreeObserver().removeGlobalOnLayoutListener(
                this);
        runnable.run();
};
view.getViewTreeObserver().addOnGlobalLayoutListener(listener);
voidinitializeDrawListener(View view)
initialize Draw Listener
System.out
        .println("FirstFrameAnimatorHelper initializeDrawListenert");
if (sGlobalDrawListener != null) {
    view.getViewTreeObserver().removeOnDrawListener(
            sGlobalDrawListener);
sGlobalDrawListener = new ViewTreeObserver.OnDrawListener() {
    private long mTime = System.currentTimeMillis();
...
voidlayoutViewAtPos(View view, int offsetX, int offsetY)
layout View At Pos
view.layout(offsetX, offsetY, offsetX + view.getMeasuredWidth(),
        offsetY + view.getMeasuredHeight());
voidmakeMultiline(View view)
make Multiline
if (view instanceof ViewGroup) {
    ViewGroup grp = (ViewGroup) view;
    for (int index = 0; index < grp.getChildCount(); index++) {
        makeMultiline(grp.getChildAt(index));
} else if (view instanceof TextView) {
    TextView t = (TextView) view;
    t.setSingleLine(false);
...
voidmeasureExactly(View view, int width, int height)
measure Exactly
int widthSpec = MeasureSpec.makeMeasureSpec(width,
        MeasureSpec.EXACTLY);
int heightSpec = MeasureSpec.makeMeasureSpec(height,
        MeasureSpec.EXACTLY);
view.measure(widthSpec, heightSpec);
voidpositionAndResizeView(View v, Rect rect)
position And Resize View
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
        v.getLayoutParams().width, v.getLayoutParams().height);
params.setMargins(rect.left, rect.top, 0, 0);
v.setLayoutParams(params);
voidshowCheatSheet(final View view)
Display a Toast letting the user know what an item does when long pressed.
final int[] screenPos = new int[2]; 
final Rect displayFrame = new Rect(); 
view.getLocationOnScreen(screenPos);
view.getWindowVisibleDisplayFrame(displayFrame);
final Context context = view.getContext();
final int viewWidth = view.getWidth();
final int viewHeight = view.getHeight();
final int viewCenterX = screenPos[0] + viewWidth / 2;
...
voidtransparent(View view, boolean transparent)
transparent
float alpha = 1;
if (transparent)
    alpha = 0.5f;
setAlpha(view, alpha);
voidviewBaseSetting(View target)
view Base Setting
target.setFadingEdgeLength(0);
target.setWillNotCacheDrawing(true);
target.setBackgroundColor(0x00000000);