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

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

源代码1 项目: Jockey   文件: BasicEmptyState.java
@Override
public final View onCreateView(RecyclerView.Adapter<EnhancedViewHolder> adapter,
                               final ViewGroup parent) {

    final View layout = LayoutInflater
            .from(parent.getContext())
            .inflate(R.layout.instance_empty, parent, false);

    parent.requestLayout();
    layout.setMinimumHeight(parent.getHeight());

    layout.findViewById(R.id.empty_button).setOnClickListener(this);
    layout.findViewById(R.id.empty_button2).setOnClickListener(this);

    return layout;
}
 
@Override
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
    super.setPrimaryItem(container, position, object);

    if (position != this.position) {
        this.position = position;
        container.requestLayout();
    }
}
 
源代码3 项目: ForPDA   文件: PaginationHelper.java
public void addInList(LayoutInflater inflater, ViewGroup target) {
    TabLayout tabLayout = (TabLayout) inflater.inflate(R.layout.pagination_list, target, false);
    target.addView(tabLayout);
    setupTabLayout(tabLayout, false);
    tabLayouts.add(tabLayout);
    target.requestLayout();
}
 
/**
 * Same as previous, but with given size in case subTreeRoot itself has layout_width or layout_height = "wrap_content"
 */
private static void wrapContentAgain(ViewGroup subTreeRoot, boolean relayoutAllNodes,
                                     int subTreeRootWidthMeasureSpec, int subTreeRootHeightMeasureSpec)
{
    assert( "main".equals( Thread.currentThread().getName() ) );

    if(subTreeRoot == null)
        return;
    LayoutParams layoutParams = subTreeRoot.getLayoutParams();

    // --- First, we force measure on the subTree
    int widthMeasureSpec 	= subTreeRootWidthMeasureSpec;
    // When LayoutParams.MATCH_PARENT and Width > 0, we apply measured width to avoid getting dimensions too big
    if( layoutParams.width  != LayoutParams.WRAP_CONTENT && subTreeRoot.getWidth() > 0 )
        widthMeasureSpec 	=  MeasureSpec.makeMeasureSpec( subTreeRoot.getWidth(), MeasureSpec.EXACTLY );
    int heightMeasureSpec 	= subTreeRootHeightMeasureSpec;
    // When LayoutParams.MATCH_PARENT and Height > 0, we apply measured height to avoid getting dimensions too big
    if( layoutParams.height != LayoutParams.WRAP_CONTENT && subTreeRoot.getHeight() > 0 )
        heightMeasureSpec 	=  MeasureSpec.makeMeasureSpec( subTreeRoot.getHeight(), MeasureSpec.EXACTLY );
    // This measure recursively the whole sub-tree
    subTreeRoot.measure( widthMeasureSpec, heightMeasureSpec );

    // --- Then recurse on all children to correct the sizes
    recurseWrapContent( subTreeRoot, relayoutAllNodes );

    // --- RequestLayout to finish properly
    subTreeRoot.requestLayout();
}
 
源代码5 项目: MiBandDecompiled   文件: DynamicDetailFragment.java
private void a(ViewGroup viewgroup, ViewGroup viewgroup1)
{
    viewgroup.setVisibility(4);
    viewgroup1.setVisibility(0);
    AnimationSet animationset = new AnimationSet(true);
    AlphaAnimation alphaanimation = new AlphaAnimation(0.0F, 1.0F);
    alphaanimation.setDuration(80L);
    animationset.addAnimation(alphaanimation);
    TranslateAnimation translateanimation = new TranslateAnimation(1, 0.0F, 1, 0.0F, 1, -1F, 1, 0.0F);
    translateanimation.setDuration(100L);
    translateanimation.setInterpolator(new DecelerateInterpolator());
    animationset.addAnimation(translateanimation);
    viewgroup1.setLayoutAnimation(new LayoutAnimationController(animationset, 0.7F));
    viewgroup1.requestLayout();
}
 
/**
 * Same as previous, but with given size in case subTreeRoot itself has layout_width or layout_height = "wrap_content"
 */
public static void wrapContentAgain( ViewGroup subTreeRoot, boolean relayoutAllNodes,
		int subTreeRootWidthMeasureSpec, int subTreeRootHeightMeasureSpec  )
{
	Log.d(TAG, "+++ LayoutWrapContentUpdater wrapContentAgain on subTreeRoot=["+ subTreeRoot +"], with w="
			+ subTreeRootWidthMeasureSpec +" and h="+ subTreeRootHeightMeasureSpec );
	assert( "main".equals( Thread.currentThread().getName() ) );
	
	if (subTreeRoot == null)
		return;
	LayoutParams layoutParams = subTreeRoot.getLayoutParams();

	// --- First, we force measure on the subTree
	int widthMeasureSpec 	= subTreeRootWidthMeasureSpec;
	// When LayoutParams.MATCH_PARENT and Width > 0, we apply measured width to avoid getting dimensions too big
	if ( layoutParams.width  != LayoutParams.WRAP_CONTENT && subTreeRoot.getWidth() > 0 )
		widthMeasureSpec 	=  MeasureSpec.makeMeasureSpec( subTreeRoot.getWidth(), MeasureSpec.EXACTLY );
	int heightMeasureSpec 	= subTreeRootHeightMeasureSpec;
	// When LayoutParams.MATCH_PARENT and Height > 0, we apply measured height to avoid getting dimensions too big
	if ( layoutParams.height != LayoutParams.WRAP_CONTENT && subTreeRoot.getHeight() > 0 )
		heightMeasureSpec 	=  MeasureSpec.makeMeasureSpec( subTreeRoot.getHeight(), MeasureSpec.EXACTLY );
	// This measure recursively the whole sub-tree
	subTreeRoot.measure( widthMeasureSpec, heightMeasureSpec ); 

	// --- Then recurse on all children to correct the sizes 
	recurseWrapContent( subTreeRoot, relayoutAllNodes );

	// --- RequestLayout to finish properly
	subTreeRoot.requestLayout();		
	return;
}
 
源代码7 项目: SwipeableLayout   文件: SwipeableLayout.java
private void resetForContainer(ViewGroup aContainer, View aChild) {
    if (aContainer.getChildAt(0).getTag() == null) return;

    aContainer.removeViewAt(0);
    aContainer.addView(aChild, 0, aChild.getLayoutParams());
    aContainer.getLayoutParams().height = LayoutParams.WRAP_CONTENT;
    aContainer.requestLayout();
}
 
@Override
public void onViewCreated(Activity activity, View headerView) {
    // Get ProgressBar and TextView. Also set initial text on TextView
    mHeaderProgressBar = (ProgressBar) headerView.findViewById(R.id.ptr_progress);
    mHeaderTextView = (TextView) headerView.findViewById(R.id.ptr_text);

    // Labels to display
    mPullRefreshLabel = activity.getString(R.string.pull_to_refresh_pull_label);
    mRefreshingLabel = activity.getString(R.string.pull_to_refresh_refreshing_label);
    mReleaseLabel = activity.getString(R.string.pull_to_refresh_release_label);

    mContentLayout = (ViewGroup) headerView.findViewById(R.id.ptr_content);
    if (mContentLayout != null) {
        mContentLayout.getLayoutParams().height = getActionBarSize(activity);
        mContentLayout.requestLayout();
    }

    Drawable abBg = getActionBarBackground(activity);
    if (abBg != null) {
        // If we do not have a opaque background we just display a solid solid behind it
        if (abBg.getOpacity() != PixelFormat.OPAQUE) {
            View view = headerView.findViewById(R.id.ptr_text_opaque_bg);
            if (view != null) {
                view.setVisibility(View.VISIBLE);
            }
        }

        mHeaderTextView.setBackgroundDrawable(abBg);
    }

    // Call onReset to make sure that the View is consistent
    onReset();
}
 
源代码9 项目: LoopBar   文件: OrientationStateVerticalLeft.java
@Override
public void initSelectionContainer(ViewGroup selectionViewContainer) {
    selectionViewContainer.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
    selectionViewContainer.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
    selectionViewContainer.requestLayout();
}
 
源代码10 项目: LoopBar   文件: OrientationStateHorizontalBottom.java
@Override
public void initSelectionContainer(ViewGroup selectionViewContainer) {
    selectionViewContainer.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
    selectionViewContainer.requestLayout();
}
 
源代码11 项目: 365browser   文件: PickerBitmapView.java
/**
 * Adds padding to the parent of the |view|.
 * @param view The child view of the view to receive the padding.
 * @param padding The amount of padding to use (in pixels).
 */
private static void addPaddingToParent(View view, int padding) {
    ViewGroup layout = (ViewGroup) view.getParent();
    layout.setPadding(padding, padding, padding, padding);
    layout.requestLayout();
}
 
@Override
public void onViewCreated(Activity activity, View headerView) {
    // Get ProgressBar and TextView. Also set initial text on TextView
    mHeaderProgressBar = (ProgressBar) headerView.findViewById(R.id.ptr_progress);
    mHeaderTextView = (TextView) headerView.findViewById(R.id.ptr_text);

    // Apply any custom ProgressBar colors
    applyProgressBarColor();

    // Labels to display
    mPullRefreshLabel = activity.getString(R.string.pull_to_refresh_pull_label);
    mRefreshingLabel = activity.getString(R.string.pull_to_refresh_refreshing_label);
    mReleaseLabel = activity.getString(R.string.pull_to_refresh_release_label);

    // Retrieve the Action Bar size from the Activity's theme
    mContentLayout = (ViewGroup) headerView.findViewById(R.id.ptr_content);
    if (mContentLayout != null) {
        mContentLayout.getLayoutParams().height = getActionBarSize(activity);
        mContentLayout.requestLayout();
    }

    // Retrieve the Action Bar background from the Activity's theme (see #93).
    Drawable abBg = getActionBarBackground(activity);
    if (abBg != null) {
        // If we do not have a opaque background we just display a solid solid behind it
        if (abBg.getOpacity() != PixelFormat.OPAQUE) {
            View view = headerView.findViewById(R.id.ptr_text_opaque_bg);
            if (view != null) {
                view.setVisibility(View.VISIBLE);
            }
        }

        mHeaderTextView.setBackgroundDrawable(abBg);
    }

    // Retrieve the Action Bar Title Style from the Action Bar's theme
    Context abContext = headerView.getContext();
    final int titleTextStyle = getActionBarTitleStyle(abContext);
    if (titleTextStyle != 0) {
        mHeaderTextView.setTextAppearance(abContext, titleTextStyle);
    }

    // Call onReset to make sure that the View is consistent
    onReset();
}
 
 方法所在类