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

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

源代码1 项目: ViewPrinter   文件: DocumentPager.java
@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");
    }
}
 
源代码2 项目: iMoney   文件: LoadingPage.java
/**
 * 初始化必要的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();
}
 
@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;
}
 
源代码4 项目: input-samples   文件: LogFragment.java
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;
}
 
源代码5 项目: Banner   文件: CustomViewHolder.java
@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;
}
 
源代码6 项目: SmoothRefreshLayout   文件: SmoothRefreshLayout.java
@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);
}
 
源代码7 项目: BaseProject   文件: BaseQuickAdapter.java
/**
 * 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;
}
 
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();
    }
}
 
源代码9 项目: VideoRecorder   文件: SurfaceViewFragment.java
/**
 * 调整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);
}
 
源代码10 项目: simple-keyboard   文件: ViewLayoutUtils.java
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);
    }
}
 
源代码11 项目: android-BeamLargeFiles   文件: LogFragment.java
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;
}
 
源代码12 项目: VideoOS-Android-SDK   文件: VenvyUIUtil.java
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;
    }
 
/**
 * @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;
    }
}
 
源代码14 项目: Nimingban   文件: AutoWrapLayout.java
public LayoutParams(ViewGroup.LayoutParams source) {
    super(source);
}
 
源代码15 项目: FlyRefresh   文件: PullHeaderLayout.java
@Override
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
    return new LayoutParams(getContext(), attrs);
}
 
源代码16 项目: android-times-square   文件: CalendarRowView.java
@Override public void addView(View child, int index, ViewGroup.LayoutParams params) {
  child.setOnClickListener(this);
  super.addView(child, index, params);
}
 
源代码17 项目: FlippableStackView   文件: OrientedViewPager.java
@Override
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
    return new LayoutParams(getContext(), attrs);
}
 
源代码18 项目: android_gisapp   文件: FloatingActionsMenu.java
@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams()
{
    return new LayoutParams(super.generateDefaultLayoutParams());
}
 
源代码19 项目: LbaizxfPulltoRefresh   文件: PullToRefreshBase.java
/**
 * 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);
}
 
源代码20 项目: Bitocle   文件: SuperCardToast.java
/**
 * 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();

    }

}
 
 方法所在类