Java Code Examples for android.support.v7.widget.RecyclerView#getLayoutParams()

The following examples show how to use android.support.v7.widget.RecyclerView#getLayoutParams() . 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: PBaseLoaderFragment.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
/**
 * 设置文件夹列表的高度
 *
 * @param mFolderListRecyclerView 文件夹列表
 * @param mImageSetMask           文件夹列表的灰色透明蒙层
 * @param isCrop                  是否是小红书样式
 */
protected void setFolderListHeight(RecyclerView mFolderListRecyclerView, View mImageSetMask, boolean isCrop) {
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mFolderListRecyclerView.getLayoutParams();
    RelativeLayout.LayoutParams maskParams = (RelativeLayout.LayoutParams) mImageSetMask.getLayoutParams();
    PickerUiConfig uiConfig = getUiConfig();
    int height = uiConfig.getFolderListOpenMaxMargin();
    if (uiConfig.getFolderListOpenDirection() == PickerUiConfig.DIRECTION_BOTTOM) {
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
        if (isCrop) {
            params.bottomMargin = bottomBar != null ? bottomBar.getViewHeight() : 0;
            params.topMargin = (titleBar != null ? titleBar.getViewHeight() : 0) + height;
            maskParams.topMargin = (titleBar != null ? titleBar.getViewHeight() : 0);
            maskParams.bottomMargin = bottomBar != null ? bottomBar.getViewHeight() : 0;
        } else {
            params.bottomMargin = 0;
            params.topMargin = height;
        }
    } else {
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
        if (isCrop) {
            params.bottomMargin = height + (bottomBar != null ? bottomBar.getViewHeight() : 0);
            params.topMargin = titleBar != null ? titleBar.getViewHeight() : 0;
            maskParams.topMargin = (titleBar != null ? titleBar.getViewHeight() : 0);
            maskParams.bottomMargin = bottomBar != null ? bottomBar.getViewHeight() : 0;
        } else {
            params.bottomMargin = height;
            params.topMargin = 0;
        }
    }
    mFolderListRecyclerView.setLayoutParams(params);
    mImageSetMask.setLayoutParams(maskParams);
}
 
Example 2
Source File: AboutAdapter.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
HeaderViewHolder(View itemView) {
    super(itemView);
    ButterKnife.bind(this, itemView);
    RecyclerView recyclerView = itemView.findViewById(R.id.recyclerview);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, true));
    recyclerView.setHasFixedSize(true);

    String[] urls = mContext.getResources().getStringArray(R.array.about_social_links);
    if (urls.length == 0) {
        recyclerView.setVisibility(View.GONE);

        subtitle.setPadding(
                subtitle.getPaddingLeft(),
                subtitle.getPaddingTop(),
                subtitle.getPaddingRight(),
                subtitle.getPaddingBottom() + mContext.getResources().getDimensionPixelSize(R.dimen.content_margin));
    } else {
        if (recyclerView.getLayoutParams() instanceof LinearLayout.LayoutParams) {
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) recyclerView.getLayoutParams();
            if (urls.length < 7) {
                params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
                params.gravity = Gravity.CENTER_HORIZONTAL;
                recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
            }
        }
        recyclerView.setAdapter(new AboutSocialAdapter(mContext, urls));
    }

    subtitle.setHtml(mContext.getResources().getString(R.string.about_desc));

    CardView card = itemView.findViewById(R.id.card);
    if (!Preferences.get(mContext).isShadowEnabled()) {
        if (card != null) card.setCardElevation(0);

        profile.setShadowRadius(0f);
        profile.setShadowColor(Color.TRANSPARENT);
    }
}
 
Example 3
Source File: SelectActivity.java    From gcm with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getIntent().getCategories() == null) {
        setResult(RESULT_CANCELED);
        finish();
    }
    setTitle(getIntent().getStringExtra(INTENT_EXTRA_TITLE));
    setContentView(R.layout.dialog_select_element);

    mRecyclerView = (RecyclerView) findViewById(R.id.select_dialog_list);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int minScreenHeight = 600;
    float activityHeightPercentage = 0.5f;
    if (metrics.heightPixels > minScreenHeight) {
        ViewGroup.LayoutParams layoutParams = mRecyclerView.getLayoutParams();
        layoutParams.height = (int) (metrics.heightPixels * activityHeightPercentage);
        mRecyclerView.setLayoutParams(layoutParams);
    }

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // use a linear layout manager
    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);

    // specify an adapter (see also next example)
    mAdapter = new SenderAdapter(this);
    mRecyclerView.setAdapter(mAdapter);

    Button addSenderButton = (Button) findViewById(R.id.select_dialog_add);
    addSenderButton.setOnClickListener(mAdapter);
}
 
Example 4
Source File: ResizeHeightPostCallback.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
@Override
public void onPostCallback(int position, T item, int itemLayoutId, ViewHelper helper) {
    RecyclerView rv ;
    if( ( rv = mWeakRecyclerView.get()) == null){
        return;
    }
    mSizeMap.put(position,rv.getLayoutManager().getDecoratedMeasuredHeight(helper.getRootView()));
    rv.getLayoutParams().height = calculateHeight(rv.getLayoutManager(),mSizeMap);
    rv.requestLayout();
}
 
Example 5
Source File: SimpleListAdapter.java    From AndroidSwipeToDelete with Apache License 2.0 2 votes vote down vote up
/**
 * adapt to the new height of the list after we swiped or added an element
 * @param context
 * @param view
 */
public void adaptHeight(@NonNull Context context, @NonNull RecyclerView view) {
    view.getLayoutParams().height = GuiUtils.calculateScrollableHeightDependOnChildren(context, getDataSize(), R.dimen.list_item_height);
}