Java Code Examples for androidx.cardview.widget.CardView#setRadius()

The following examples show how to use androidx.cardview.widget.CardView#setRadius() . 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: AlohaActivity.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
/**
 * 设置简单图片适配器
 *
 * @param imageItems 图片信息列表
 */
public void setImageViewList(@Nullable List<? extends ImageItem> imageItems) {
    if (imageItems == null) {
        return;
    }
    if (viewList == null) {
        viewList = new ArrayList<>();
    } else {
        viewList.clear();
    }
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    for (final ImageItem entity : imageItems) {
        CardView cardView = new CardView(this);
        cardView.setCardElevation(dp(2));
        cardView.setRadius(dp(5));
        cardView.setLayoutParams(params);

        CropImageView imageView = new CropImageView(this);
        imageView.setLayoutParams(params);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        if (entity.getCropUrl() != null && entity.getCropUrl().length() > 0) {
            Glide.with(this).load(entity.getCropUrl()).into(imageView);
        } else {
            Glide.with(this).load(entity.path).into(imageView);
        }
        cardView.addView(imageView);
        viewList.add(cardView);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intentCrop(entity);
            }
        });
    }
    setViewList(viewList);
}
 
Example 2
Source File: AdvanceDrawerLayout.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
public void addView(View child) {
    if (child instanceof NavigationView) {
        super.addView(child);
    } else {
        CardView cardView = new CardView(getContext());
        cardView.setRadius(0);
        cardView.addView(child);
        cardView.setCardElevation(0);
        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            cardView.setContentPadding(-6, -9, -6, -9);
        }
        frameLayout.addView(cardView);
    }
}
 
Example 3
Source File: AbstractMainCardViewHolder.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@CallSuper
public void onBindView(GeoActivity activity, @NonNull Location location,
                       @NonNull ResourceProvider provider,
                       boolean listAnimationEnabled, boolean itemAnimationEnabled, boolean firstCard) {
    super.onBindView(activity, location, provider, listAnimationEnabled, itemAnimationEnabled);

    CardView card = (CardView) itemView;

    card.setRadius(themeManager.getCardRadius(activity));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        card.setElevation(themeManager.getCardElevation(activity));
    }

    ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) card.getLayoutParams();
    params.setMargins(
            themeManager.getCardMarginsHorizontal(activity),
            0,
            themeManager.getCardMarginsHorizontal(activity),
            themeManager.getCardMarginsVertical(activity)
    );
    card.setLayoutParams(params);

    if (firstCard) {
        firstCardHeaderController = new FirstCardHeaderController(activity, location);
        firstCardHeaderController.bind((LinearLayout) card.getChildAt(0));
    }
}
 
Example 4
Source File: RecyclerViewAdapter.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
    RecyclerViewItem item = mItems.get(position);
    View view;
    if (item.cacheable()) {
        if (mViews.containsKey(item)) {
            view = mViews.get(item);
        } else {
            mViews.put(item, view = LayoutInflater.from(parent.getContext())
                    .inflate(item.getLayoutRes(), parent, false));
        }
    } else {
        try {
            view = LayoutInflater.from(parent.getContext())
                    .inflate(item.getLayoutRes(), parent, false);
        } catch (Exception ignored) {
            throw new IllegalArgumentException("Couldn't inflate " + item.getClass().getSimpleName());
        }
    }
    ViewGroup viewGroup = (ViewGroup) view.getParent();
    if (viewGroup != null) {
        viewGroup.removeView(view);
    }
    if (item.cardCompatible() && AppSettings.isForceCards(parent.getContext())) {
        CardView cardView =
                new CardView(view.getContext());
        cardView.setRadius(view.getResources().getDimension(R.dimen.cardview_radius));
        cardView.setCardElevation(view.getResources().getDimension(R.dimen.cardview_elevation));
        cardView.setUseCompatPadding(true);
        cardView.setFocusable(false);
        cardView.addView(view);
        view = cardView;
    }
    if (position == 0) {
        mFirstItem = view;
    }
    item.setOnViewChangeListener(mOnViewChangedListener);
    item.onCreateHolder(parent, view);

    return new RecyclerView.ViewHolder(view) {
    };
}