Java Code Examples for androidx.cardview.widget.CardView#setCardElevation()
The following examples show how to use
androidx.cardview.widget.CardView#setCardElevation() .
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: NoteViewHolder.java From science-journal with Apache License 2.0 | 6 votes |
public NoteViewHolder(View v) { super(v); durationText = (TextView) v.findViewById(R.id.time_text); menuButton = (ImageButton) v.findViewById(R.id.note_menu_button); text = (TextView) v.findViewById(R.id.note_text); image = (ImageView) v.findViewById(R.id.note_image); captionIcon = (ImageView) v.findViewById(R.id.edit_icon); captionView = itemView.findViewById(R.id.caption_section); captionTextView = (TextView) itemView.findViewById(R.id.caption); valuesList = (ViewGroup) itemView.findViewById(R.id.snapshot_values_list); relativeTimeView = (RelativeTimeTextView) itemView.findViewById(R.id.relative_time_text); CardView cardView = v.findViewById(R.id.card_view); cardView.setUseCompatPadding(true); cardView.setCardElevation(0); cardView.setBackground( cardView.getResources().getDrawable(R.drawable.card_view_with_hairline_border)); }
Example 2
Source File: MapLayerListFragment.java From geopaparazzi with GNU General Public License v3.0 | 6 votes |
@Override public void onBindDragView(View clickedView, View dragView) { CharSequence name = ((TextView) clickedView.findViewById(R.id.nameView)).getText(); ((TextView) dragView.findViewById(R.id.nameView)).setText(name); CharSequence path = ((TextView) clickedView.findViewById(R.id.pathView)).getText(); ((TextView) dragView.findViewById(R.id.pathView)).setText(path); boolean enabled = ((CheckBox) clickedView.findViewById(R.id.enableCheckbox)).isChecked(); ((CheckBox) dragView.findViewById(R.id.enableCheckbox)).setChecked(enabled); CardView dragCard = dragView.findViewById(R.id.card); CardView clickedCard = clickedView.findViewById(R.id.card); dragCard.setMaxCardElevation(40); dragCard.setCardElevation(clickedCard.getCardElevation()); // I know the dragView is a FrameLayout and that is why I can use setForeground below api level 23 dragCard.setForeground(clickedView.getResources().getDrawable(R.drawable.card_view_drag_foreground)); }
Example 3
Source File: AlohaActivity.java From YImagePicker with Apache License 2.0 | 5 votes |
/** * 设置简单图片适配器 * * @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 4
Source File: AdvanceDrawerLayout.java From Drawer-Behavior with MIT License | 5 votes |
@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 5
Source File: ExperimentDetailsFragment.java From science-journal with Apache License 2.0 | 5 votes |
@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view; LayoutInflater inflater = LayoutInflater.from(parent.getContext()); if (viewType == VIEW_TYPE_EXPERIMENT_TEXT_LABEL || viewType == VIEW_TYPE_EXPERIMENT_PICTURE_LABEL || viewType == VIEW_TYPE_EXPERIMENT_TRIGGER_LABEL || viewType == VIEW_TYPE_SNAPSHOT_LABEL || viewType == VIEW_TYPE_SKETCH) { view = inflater.inflate(R.layout.exp_card_pinned_note, parent, false); return new NoteViewHolder(view); } else if (viewType == VIEW_TYPE_RECORDING) { view = inflater.inflate(R.layout.exp_card_recording, parent, false); return new RecordingViewHolder(view); } else if (viewType == VIEW_TYPE_EXPERIMENT_ARCHIVED) { view = inflater.inflate(R.layout.metadata_archived, parent, false); } else if (viewType == VIEW_TYPE_RUN_CARD) { view = inflater.inflate(R.layout.exp_card_run, parent, false); } else { // TODO(b/117987511): display a card that explains why we can't show this data view = inflater.inflate(R.layout.exp_card_empty, parent, false); } CardView cardView = view.findViewById(R.id.card_view); if (cardView != null) { cardView.setUseCompatPadding(true); cardView.setCardElevation(0); cardView.setBackground( cardView.getResources().getDrawable(R.drawable.card_view_with_hairline_border)); } return new DetailsViewHolder(view, viewType); }
Example 6
Source File: BoardFragment.java From DragListView with Apache License 2.0 | 5 votes |
@Override public void onBindDragView(View clickedView, View dragView) { CharSequence text = ((TextView) clickedView.findViewById(R.id.text)).getText(); ((TextView) dragView.findViewById(R.id.text)).setText(text); CardView dragCard = dragView.findViewById(R.id.card); CardView clickedCard = clickedView.findViewById(R.id.card); dragCard.setMaxCardElevation(40); dragCard.setCardElevation(clickedCard.getCardElevation()); // I know the dragView is a FrameLayout and that is why I can use setForeground below api level 23 dragCard.setForeground(clickedView.getResources().getDrawable(R.drawable.card_view_drag_foreground)); }
Example 7
Source File: ShadowTransformation.java From adamant-android with GNU General Public License v3.0 | 4 votes |
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { int realCurrentPosition; int nextPosition; float baseElevation = mAdapter.getBaseElevation(); float realOffset; boolean goingLeft = mLastOffset > positionOffset; // If we're going backwards, onPageScrolled receives the last position // instead of the current one if (goingLeft) { realCurrentPosition = position + 1; nextPosition = position; realOffset = 1 - positionOffset; } else { nextPosition = position + 1; realCurrentPosition = position; realOffset = positionOffset; } // Avoid crash on overscroll if (nextPosition > mAdapter.getCount() - 1 || realCurrentPosition > mAdapter.getCount() - 1) { return; } CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition); // This might be null if a fragment is being used // and the views weren't created yet if (currentCard != null) { if (mScalingEnabled) { currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset))); currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset))); } currentCard.setCardElevation((baseElevation + baseElevation * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset))); } CardView nextCard = mAdapter.getCardViewAt(nextPosition); // We might be scrolling fast enough so that the next (or previous) card // was already destroyed or a fragment might not have been created yet if (nextCard != null) { if (mScalingEnabled) { nextCard.setScaleX((float) (1 + 0.1 * (realOffset))); nextCard.setScaleY((float) (1 + 0.1 * (realOffset))); } nextCard.setCardElevation((baseElevation + baseElevation * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset))); } mLastOffset = positionOffset; }
Example 8
Source File: RecyclerViewAdapter.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 4 votes |
@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) { }; }