Java Code Examples for android.view.ViewGroup#requestLayout()

The following examples show how to use android.view.ViewGroup#requestLayout() . 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: BasicEmptyState.java    From Jockey with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: HeightablePagerAdapter.java    From ColorPickerDialog with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 3
Source File: PaginationHelper.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 4
Source File: LayoutWrapContentUpdater.java    From MaterialScrollBar with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 5
Source File: DynamicDetailFragment.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 6
Source File: LayoutWrapContentUpdater.java    From android-layout-wrap-content-updater with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: SwipeableLayout.java    From SwipeableLayout with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 8
Source File: PullToRefreshAttacher.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 9
Source File: OrientationStateVerticalLeft.java    From LoopBar with MIT License 4 votes vote down vote up
@Override
public void initSelectionContainer(ViewGroup selectionViewContainer) {
    selectionViewContainer.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
    selectionViewContainer.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
    selectionViewContainer.requestLayout();
}
 
Example 10
Source File: OrientationStateHorizontalBottom.java    From LoopBar with MIT License 4 votes vote down vote up
@Override
public void initSelectionContainer(ViewGroup selectionViewContainer) {
    selectionViewContainer.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
    selectionViewContainer.requestLayout();
}
 
Example 11
Source File: PickerBitmapView.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * 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();
}
 
Example 12
Source File: DefaultHeaderTransformer.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@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();
}