Java Code Examples for android.view.ViewGroup#LayoutParams

The following examples show how to use android.view.ViewGroup#LayoutParams . 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: ActionMenuPresenter.java    From Libraries-for-Android-Developers with MIT License 6 votes vote down vote up
@Override
public View getItemView(MenuItemImpl item, View convertView, ViewGroup parent) {
    View actionView = item.getActionView();
    if (actionView == null || item.hasCollapsibleActionView()) {
        if (!(convertView instanceof ActionMenuItemView)) {
            convertView = null;
        }
        actionView = super.getItemView(item, convertView, parent);
    }
    actionView.setVisibility(item.isActionViewExpanded() ? View.GONE : View.VISIBLE);

    final ActionMenuView menuParent = (ActionMenuView) parent;
    final ViewGroup.LayoutParams lp = actionView.getLayoutParams();
    if (!menuParent.checkLayoutParams(lp)) {
        actionView.setLayoutParams(menuParent.generateLayoutParams(lp));
    }
    return actionView;
}
 
Example 2
Source File: DocumentPager.java    From ViewPrinter with Apache License 2.0 6 votes vote down vote up
@Override
public void take(View view, ViewGroup.LayoutParams params) {
    ensureFirstPage();
    DocumentPage page = getLastPage();
    LOG.i("take:", "view:", Utils.mark(view), "dispatching to page", page.getNumber());
    boolean empty = page.getChildCount() == 0;
    if (page.canTake(view, params, false)) {
        page.take(view, params);
    } else if (!empty) {
        // Could not take but had views. Open another.
        LOG.i("take:", "view:", Utils.mark(view), "could not take. Opening another.");
        openPage();
        take(view, params);
    } else {
        // This view is untakable, doesn't fit the page size.
        // Pass anyway, it will be cropped but who cares.
        LOG.w("take:", "view:", Utils.mark(view), "is untakable, appending to page", getLastPage().getNumber());
        Utils.setUntakable(view, true);
        getLastPage().take(view, params);
        LOG.e("take:",
                "Got a child but it is too tall to fit a single page.",
                "Please split into multiple childs");
    }
}
 
Example 3
Source File: LoadingPage.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化必要的View,并指明视图显示宽高的参数
 */
private void init() {
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    if (view_loading == null) {
        view_loading = UIUtils.getView(R.layout.page_loading);
        addView(view_loading, params);
    }
    if (view_error == null) {
        view_error = UIUtils.getView(R.layout.page_error);
        addView(view_error, params);
    }
    if (view_empty == null) {
        view_empty = UIUtils.getView(R.layout.page_empty);
        addView(view_empty, params);
    }

    showSafePage();
}
 
Example 4
Source File: GridViewWithHeaderAndFooter.java    From android-GridViewWithHeaderAndFooter with Apache License 2.0 5 votes vote down vote up
public void addFooterView(View v, Object data, boolean isSelectable) {
    ListAdapter mAdapter = getAdapter();
    if (mAdapter != null && !(mAdapter instanceof HeaderViewGridAdapter)) {
        throw new IllegalStateException(
                "Cannot add header view to grid -- setAdapter has already been called.");
    }

    ViewGroup.LayoutParams lyp = v.getLayoutParams();

    FixedViewInfo info = new FixedViewInfo();
    FrameLayout fl = new FullWidthFixedViewLayout(getContext());

    if (lyp != null) {
        v.setLayoutParams(new FrameLayout.LayoutParams(lyp.width, lyp.height));
        fl.setLayoutParams(new AbsListView.LayoutParams(lyp.width, lyp.height));
    }
    fl.addView(v);
    info.view = v;
    info.viewContainer = fl;
    info.data = data;
    info.isSelectable = isSelectable;
    mFooterViewInfos.add(info);

    if (mAdapter != null) {
        ((HeaderViewGridAdapter) mAdapter).notifyDataSetChanged();
    }
}
 
Example 5
Source File: AbstractLayoutManagerUtils.java    From tenor-android-core with Apache License 2.0 5 votes vote down vote up
/**
 * @return the span index of {@link StaggeredGridLayoutManager.LayoutParams} and {@link GridLayoutManager.LayoutParams},
 * otherwise 1 for all other {@link ViewGroup.LayoutParams}
 */
public static <T extends ViewGroup.LayoutParams> int getSpanIndex(@Nullable final T layoutParams) {
    if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) {
        return ((StaggeredGridLayoutManager.LayoutParams) layoutParams).getSpanIndex();
    } else if (layoutParams instanceof GridLayoutManager.LayoutParams) {
        return ((GridLayoutManager.LayoutParams) layoutParams).getSpanIndex();
    } else {
        return -1;
    }
}
 
Example 6
Source File: VenvyUIUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public static boolean addViewToWindow(Context context, View view, ViewGroup.LayoutParams params) {

        if (null == view || null == context || !removeViewFromParent(view)) {
            return false;
        }

        final WindowManager manager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        addView(view, params, manager);
        return true;
    }
 
Example 7
Source File: LogFragment.java    From android-BeamLargeFiles with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 8
Source File: ViewLayoutUtils.java    From simple-keyboard with Apache License 2.0 5 votes vote down vote up
public static void placeViewAt(final View view, final int x, final int y, final int w,
        final int h) {
    final ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (lp instanceof MarginLayoutParams) {
        final MarginLayoutParams marginLayoutParams = (MarginLayoutParams)lp;
        marginLayoutParams.width = w;
        marginLayoutParams.height = h;
        marginLayoutParams.setMargins(x, y, -50, 0);
    }
}
 
Example 9
Source File: SurfaceViewFragment.java    From VideoRecorder with Apache License 2.0 5 votes vote down vote up
/**
 * 调整SurfaceView的大小比例 , 以避免预览变形
 *
 * @param previewSize 预览大小
 */
private void adjustSurfaceViewSize(Size previewSize) {
    int width = getResources().getDisplayMetrics().widthPixels;
    int height = (int) (width * ((previewSize.getWidth() * 1.0f) / previewSize.getHeight()));
    ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) mSurfaceView.getLayoutParams();
    lp.width = width;
    lp.height = height;
    mSurfaceView.setLayoutParams(lp);
}
 
Example 10
Source File: LogFragment.java    From input-samples with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 11
Source File: BaseQuickAdapter.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/**
 * added by fee 2019-07-11:
 * <P>注:该方法主要是用来relayout适配的itemView布局,依赖的前提条件为外部指定了itemView的宽、高</P>
 * 为了满足某些场景下,需要通过外部来重新指定item view的宽、高,则在{convert(xx,xx)}
 * 需要重新设置item view的布局参数
 * @param assignTagId 所指定的给 theItemView setTag()用于标记已经relayout过的
 * @param theItemView 当前的item 视图
 * @return true:重置了itemview布局
 */
protected boolean relayoutTheItemView(@IdRes int assignTagId, View theItemView) {
    if (theAssignItemHeight == 0 && theAssignItemWidth == 0) {
        return false;
    }
    if (theItemView == null) {
        return false;
    }
    Object relayoutTag = theItemView.getTag(assignTagId);
    if (relayoutTag != null) {//已经relayout了当前的item view,则不进行relayout了
        return false;
    }
    startRelayoutItemView(theItemView);//这里回调出去主要是为了如果有额外的处理,则给机会处理,然后最后统一setLayoutParams
    ViewGroup.LayoutParams vlp = theItemView.getLayoutParams();
    if (vlp == null) {
        vlp = new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    }
    if (theAssignItemWidth > 0) {//一般宽较容易确定
        vlp.width = theAssignItemWidth;
    }
    if (theAssignUiDesignWidthRatio != 0 && theAssignUiDesignHeightRatio != 0 && theAssignItemWidth > 0) {
        //h实 = w实 * h设计高占比 /w设计宽占比:即等比缩放itemView宽高
        theAssignItemHeight = theAssignItemWidth * theAssignUiDesignHeightRatio / theAssignUiDesignWidthRatio;
    }
    if (theAssignItemHeight > 0) {
        vlp.height = theAssignItemHeight;
    }
    theItemView.setTag(assignTagId, "relayouted");
    theItemView.setLayoutParams(vlp);
    return true;
}
 
Example 12
Source File: SmoothRefreshLayout.java    From SmoothRefreshLayout with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
@CallSuper
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (params == null) {
        params = generateDefaultLayoutParams();
    } else {
        params = generateLayoutParams(params);
    }
    if (child instanceof IRefreshView) {
        IRefreshView<IIndicator> view = (IRefreshView<IIndicator>) child;
        switch (view.getType()) {
            case IRefreshView.TYPE_HEADER:
                if (mHeaderView != null)
                    throw new IllegalArgumentException(
                            "Unsupported operation, HeaderView only can be add once !!");
                mHeaderView = view;
                break;
            case IRefreshView.TYPE_FOOTER:
                if (mFooterView != null)
                    throw new IllegalArgumentException(
                            "Unsupported operation, FooterView only can be add once !!");
                mFooterView = view;
                break;
        }
    }
    super.addView(child, index, params);
}
 
Example 13
Source File: CustomViewHolder.java    From Banner with Apache License 2.0 5 votes vote down vote up
@Override
public View createView(Context context, int position, Object data) {
    // 返回mImageView页面布局
    ImageView imageView = new ImageView(context);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
    );
    imageView.setLayoutParams(params);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);

    Glide.with(context).load(data).into(imageView);

    return imageView;
}
 
Example 14
Source File: CalendarRowView.java    From android-times-square with Apache License 2.0 4 votes vote down vote up
@Override public void addView(View child, int index, ViewGroup.LayoutParams params) {
  child.setOnClickListener(this);
  super.addView(child, index, params);
}
 
Example 15
Source File: OrientedViewPager.java    From FlippableStackView with Apache License 2.0 4 votes vote down vote up
@Override
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
    return new LayoutParams(getContext(), attrs);
}
 
Example 16
Source File: FloatingActionsMenu.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams()
{
    return new LayoutParams(super.generateDefaultLayoutParams());
}
 
Example 17
Source File: PullHeaderLayout.java    From FlyRefresh with MIT License 4 votes vote down vote up
@Override
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
    return new LayoutParams(getContext(), attrs);
}
 
Example 18
Source File: AutoWrapLayout.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
public LayoutParams(ViewGroup.LayoutParams source) {
    super(source);
}
 
Example 19
Source File: PullToRefreshBase.java    From LbaizxfPulltoRefresh with Apache License 2.0 2 votes vote down vote up
/**
 * Used internally for adding view. Need because we override addView to
 * pass-through to the Refreshable View
 */
protected final void addViewInternal(View child, int index, ViewGroup.LayoutParams params) {
	super.addView(child, index, params);
}
 
Example 20
Source File: SuperCardToast.java    From Bitocle with Apache License 2.0 2 votes vote down vote up
/**
 * Hide the SuperCardToast and animate the Layout. Post Honeycomb only. *
 */
@SuppressLint("NewApi")
private void dismissWithLayoutAnimation() {

    if (mToastView != null) {

        mToastView.setVisibility(View.INVISIBLE);

        final ViewGroup.LayoutParams layoutParams = mToastView.getLayoutParams();
        final int originalHeight = mToastView.getHeight();

        ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1)
                .setDuration(mActivity.getResources().getInteger(android.R.integer.config_shortAnimTime));

        animator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {

                Handler mHandler = new Handler();
                mHandler.post(mHideImmediateRunnable);

            }

        });

        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            @SuppressWarnings("ConstantConditions")
            public void onAnimationUpdate(ValueAnimator valueAnimator) {

                if (mToastView != null) {

                    try {

                        layoutParams.height = (Integer) valueAnimator.getAnimatedValue();
                        mToastView.setLayoutParams(layoutParams);

                    } catch (NullPointerException e) {

                        /* Do nothing */

                    }


                }

            }

        });

        animator.start();

    } else {

        dismissImmediately();

    }

}