下面列出了android.support.v7.widget.CardView#getLayoutParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void convert(BaseViewHolder helper, FunBean item) {
CardView cardView = helper.getView(R.id.card);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) cardView.getLayoutParams();
layoutParams.setMarginStart(item.getMarginStart());
layoutParams.setMarginEnd(item.getMarginEnd());
helper.setText(R.id.tvName, item.getName());
ImageView ivIcon = helper.getView(R.id.ivIcon);
ImageView ivFlower = helper.getView(R.id.ivFlower);
ivFlower.setImageResource(item.getFlower());
Glide.with(mContext).load(item.getPic()).into(ivIcon);
}
@Override
public void onBindItemHolder(SuperViewHolder holder, int position) {
CardView cardView = holder.getView(R.id.card_view);
TextView textView = holder.getView(R.id.info_text);
ItemModel itemModel = mDataList.get(position);
textView.setText(itemModel.title);
//修改高度,模拟交错效果
cardView.getLayoutParams().height = itemModel.height;
}
ContributorsViewHolder(View itemView) {
super(itemView);
TextView title = itemView.findViewById(R.id.title);
CardView card = itemView.findViewById(R.id.card);
if (CandyBarApplication.getConfiguration().getAboutStyle() == CandyBarApplication.Style.PORTRAIT_FLAT_LANDSCAPE_FLAT &&
card != null) {
if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
card.setRadius(0f);
card.setUseCompatPadding(false);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams();
params.setMargins(0, 0, margin, margin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
}
}
if (!Preferences.get(mContext).isCardShadowEnabled()) {
if (card != null) card.setCardElevation(0);
}
int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary);
title.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable(
mContext, R.drawable.ic_toolbar_people, color), null, null, null);
title.setText(mContext.getResources().getString(R.string.about_contributors_title));
title.setOnClickListener(this);
}
ContentViewHolder(View itemView) {
super(itemView);
container = itemView.findViewById(R.id.container);
autoFitTitle = itemView.findViewById(R.id.title);
subtitle = itemView.findViewById(R.id.subtitle);
CardView card = itemView.findViewById(R.id.card);
if (CandyBarApplication.getConfiguration().getHomeGrid() == CandyBarApplication.GridStyle.FLAT) {
if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
card.setRadius(0f);
card.setUseCompatPadding(false);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams();
params.setMargins(0, 0, margin, margin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
}
}
if (!Preferences.get(mContext).isCardShadowEnabled()) {
card.setCardElevation(0);
}
container.setOnClickListener(this);
}
IconRequestViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
installedApps = itemView.findViewById(R.id.installed_apps);
missedApps = itemView.findViewById(R.id.missed_apps);
themedApps = itemView.findViewById(R.id.themed_apps);
progress = itemView.findViewById(R.id.progress);
container = itemView.findViewById(R.id.container);
CardView card = itemView.findViewById(R.id.card);
if (CandyBarApplication.getConfiguration().getHomeGrid() == CandyBarApplication.GridStyle.FLAT) {
if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
card.setRadius(0f);
card.setUseCompatPadding(false);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams();
params.setMargins(0, 0, margin, margin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
}
}
if (!Preferences.get(mContext).isCardShadowEnabled()) {
card.setCardElevation(0);
}
int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary);
title.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable(
mContext, R.drawable.ic_toolbar_icon_request, color), null, null, null);
int accent = ColorHelper.getAttributeColor(mContext, R.attr.colorAccent);
progress.getProgressDrawable().setColorFilter(accent, PorterDuff.Mode.SRC_IN);
container.setOnClickListener(this);
}
WallpapersViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
TextView muzei = itemView.findViewById(R.id.muzei);
CardView card = itemView.findViewById(R.id.card);
if (CandyBarApplication.getConfiguration().getHomeGrid() == CandyBarApplication.GridStyle.FLAT) {
if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
card.setRadius(0f);
card.setUseCompatPadding(false);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams();
params.setMargins(0, 0, margin, margin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
}
}
if (!Preferences.get(mContext).isCardShadowEnabled()) {
card.setCardElevation(0);
}
int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary);
title.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable(
mContext, R.drawable.ic_toolbar_wallpapers, color), null, null, null);
muzei.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.get(
mContext, R.drawable.ic_home_app_muzei), null, null, null);
title.setOnClickListener(this);
muzei.setOnClickListener(this);
}
GooglePlayDevViewHolder(View itemView) {
super(itemView);
container = itemView.findViewById(R.id.container);
title = itemView.findViewById(R.id.title);
CardView card = itemView.findViewById(R.id.card);
if (CandyBarApplication.getConfiguration().getHomeGrid() == CandyBarApplication.GridStyle.FLAT) {
if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
card.setRadius(0f);
card.setUseCompatPadding(false);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams();
params.setMargins(0, 0, margin, margin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
}
}
if (!Preferences.get(mContext).isCardShadowEnabled()) {
card.setCardElevation(0);
}
int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary);
title.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable(
mContext, R.drawable.ic_google_play_more_apps, color), null, null, null);
container.setOnClickListener(this);
}
ContentViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.name);
content = itemView.findViewById(R.id.requested);
icon = itemView.findViewById(R.id.icon);
checkbox = itemView.findViewById(R.id.checkbox);
container = itemView.findViewById(R.id.container);
divider = itemView.findViewById(R.id.divider);
CardView card = itemView.findViewById(R.id.card);
if (CandyBarApplication.getConfiguration().getRequestStyle() == CandyBarApplication.Style.PORTRAIT_FLAT_LANDSCAPE_FLAT &&
card != null) {
if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
card.setRadius(0f);
card.setUseCompatPadding(false);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams();
params.setMargins(0, 0, margin, margin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
}
}
if (!Preferences.get(mContext).isCardShadowEnabled()) {
if (card != null) card.setCardElevation(0);
}
container.setOnClickListener(this);
container.setOnLongClickListener(this);
}
ViewHolder(View itemView, int viewType) {
super(itemView);
if (viewType == TYPE_HEADER) {
name = itemView.findViewById(R.id.name);
holderId = TYPE_HEADER;
} else if (viewType == TYPE_CONTENT) {
icon = itemView.findViewById(R.id.icon);
name = itemView.findViewById(R.id.name);
container = itemView.findViewById(R.id.container);
CardView card = itemView.findViewById(R.id.card);
if (CandyBarApplication.getConfiguration().getApplyGrid() == CandyBarApplication.GridStyle.FLAT) {
if (card.getLayoutParams() instanceof GridLayoutManager.LayoutParams) {
card.setRadius(0f);
card.setUseCompatPadding(false);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) card.getLayoutParams();
params.setMargins(0, 0, margin, margin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
}
}
if (!Preferences.get(mContext).isCardShadowEnabled()) {
if (card != null) card.setCardElevation(0);
}
holderId = TYPE_CONTENT;
container.setOnClickListener(this);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_person_detail);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
setTitle("");
Intent receivedIntent = getIntent();
mPersonId = receivedIntent.getIntExtra(Constants.PERSON_ID, -1);
if (mPersonId == -1) finish();
mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
mCastImageCardView = (CardView) findViewById(R.id.card_view_cast_detail);
mCastImageSideSize = (int) (getResources().getDisplayMetrics().widthPixels * 0.33);
mCastImageCardView.getLayoutParams().height = mCastImageSideSize;
mCastImageCardView.getLayoutParams().width = mCastImageSideSize;
mCastImageCardView.setRadius(mCastImageSideSize / 2);
mCastImageView = (ImageView) findViewById(R.id.image_view_cast_detail);
mProgressBar = (AVLoadingIndicatorView) findViewById(R.id.progress_bar_cast_detail);
mProgressBar.setVisibility(View.GONE);
mCastNameTextView = (TextView) findViewById(R.id.text_view_name_cast_detail);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mCastNameTextView.getLayoutParams();
params.setMargins(params.leftMargin, mCastImageSideSize / 2, params.rightMargin, params.bottomMargin);
mCastAgeTextView = (TextView) findViewById(R.id.text_view_age_cast_detail);
mCastBirthPlaceTextView = (TextView) findViewById(R.id.text_view_birthplace_cast_detail);
mBackImageButton = (ImageButton) findViewById(R.id.image_button_back_cast_detail);
mBackImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
mCastBioHeaderTextView = (TextView) findViewById(R.id.text_view_bio_header_person_detail);
mCastBioTextView = (TextView) findViewById(R.id.text_view_bio_person_detail);
mCastReadMoreBioTextView = (TextView) findViewById(R.id.text_view_read_more_person_detail);
mMovieCastTextView = (TextView) findViewById(R.id.text_view_movie_cast_person_detail);
mMovieCastRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_movie_cast_person_detail);
mMovieCastOfPersons = new ArrayList<>();
mMovieCastsOfPersonAdapter = new MovieCastsOfPersonAdapter(PersonDetailActivity.this, mMovieCastOfPersons);
mMovieCastRecyclerView.setAdapter(mMovieCastsOfPersonAdapter);
mMovieCastRecyclerView.setLayoutManager(new LinearLayoutManager(PersonDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));
mTVCastTextView = (TextView) findViewById(R.id.text_view_tv_cast_person_detail);
mTVCastRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_tv_cast_person_detail);
mTVCastOfPersons = new ArrayList<>();
mTVCastsOfPersonAdapter = new TVCastsOfPersonAdapter(PersonDetailActivity.this, mTVCastOfPersons);
mTVCastRecyclerView.setAdapter(mTVCastsOfPersonAdapter);
mTVCastRecyclerView.setLayoutManager(new LinearLayoutManager(PersonDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));
if (NetworkConnection.isConnected(PersonDetailActivity.this)) {
isActivityLoaded = true;
loadActivity();
}
}
private void init(Context context){
mMenus = new ArrayList<MenuBean>();
mMenuAdapter = new MenuAdapter(mContext, mMenus, mLayoutManagerOrientation);
mMenuAdapter.setMenuWidth(mWidth);
mMenuAdapter.setTextPaddingLeft(mMenuTextPaddingLeft);
mMenuAdapter.setTextPaddingBottom(mMenuTextPaddingBottom);
mMenuAdapter.setTextPaddingRight(mMenuTextPaddingRight);
mMenuAdapter.setTextPaddingTop(mMenuTextPaddingTop);
mMenuAdapter.setDividerDp(mMenuDividerDp);
mMenuAdapter.setDividerColor(mDividerColor);
mMenuAdapter.setExpandableIcon(mExpandableIcon);
mMenuAdapter.setMenuTextColor(mMenuTextColor);
mMenuAdapter.setHorizontalMenuBackgroundRes(mHorizontalMenuBackgroundRes);
mMenuAdapter.setVerticalMenuBackgroundRes(mVerticalMenuBackgroundRes);
mMenuAdapter.setMenuTextSize(mMenuTextSize);
mMenuAdapter.setOnMenuClickListener(new OnMenuClickListener() {
@Override
public void onMenuClick(int level1Index, int level2Index, int level3Index) {
dealMenuClickEvent(level1Index, level2Index, level3Index);
}
});
mLayoutManager = new LinearLayoutManager(mContext);
mLayoutManager.setOrientation(mLayoutManagerOrientation);
mRootView = LayoutInflater.from(mContext).inflate(R.layout.view_menu_container, null);
mCardView = (CardView) mRootView.findViewById(R.id.cardView);
mCardView.setCardBackgroundColor(mMenuLayoutBgColor);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mCardView.getLayoutParams();
if (mWidth != -1){
params.width = mWidth;
}
if (mHeight != -1){
params.height = mHeight;
}
mCardView.setLayoutParams(params);
mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.recyclerView);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mMenuAdapter);
setContentView(mRootView);
setWidth(RelativeLayout.LayoutParams.WRAP_CONTENT);
setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
setFocusable(true);
setAnimationStyle(mAnimStyle);
setBackgroundDrawable(new ColorDrawable(0x00000000));
}
FooterViewHolder(View itemView) {
super(itemView);
ImageView instagram = itemView.findViewById(R.id.about_dev_instagram);
ImageView googlePlus = itemView.findViewById(R.id.about_dev_google_plus);
ImageView github = itemView.findViewById(R.id.about_dev_github);
TextView title = itemView.findViewById(R.id.about_dashboard_title);
TextView licenses = itemView.findViewById(R.id.about_dashboard_licenses);
TextView contributors = itemView.findViewById(R.id.about_dashboard_contributors);
TextView translator = itemView.findViewById(R.id.about_dashboard_translator);
CardView card = itemView.findViewById(R.id.card);
if (CandyBarApplication.getConfiguration().getAboutStyle() == CandyBarApplication.Style.PORTRAIT_FLAT_LANDSCAPE_FLAT &&
card != null) {
if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
card.setRadius(0f);
card.setUseCompatPadding(false);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams();
params.setMargins(0, 0, margin, margin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
}
}
if (!Preferences.get(mContext).isCardShadowEnabled()) {
if (card != null) card.setCardElevation(0);
}
int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary);
title.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable(
mContext, R.drawable.ic_toolbar_dashboard, color), null, null, null);
color = ConfigurationHelper.getSocialIconColor(mContext,
CandyBarApplication.getConfiguration().getSocialIconColor());
instagram.setImageDrawable(DrawableHelper.getTintedDrawable(mContext, R.drawable.ic_toolbar_instagram, color));
googlePlus.setImageDrawable(DrawableHelper.getTintedDrawable(mContext, R.drawable.ic_toolbar_google_plus, color));
github.setImageDrawable(DrawableHelper.getTintedDrawable(mContext, R.drawable.ic_toolbar_github, color));
instagram.setOnClickListener(this);
googlePlus.setOnClickListener(this);
github.setOnClickListener(this);
licenses.setOnClickListener(this);
contributors.setOnClickListener(this);
translator.setOnClickListener(this);
}
HeaderViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
content = itemView.findViewById(R.id.content);
button = itemView.findViewById(R.id.buy);
container = itemView.findViewById(R.id.premium_request);
total = itemView.findViewById(R.id.premium_request_total);
available = itemView.findViewById(R.id.premium_request_available);
used = itemView.findViewById(R.id.premium_request_used);
progress = itemView.findViewById(R.id.progress);
CardView card = itemView.findViewById(R.id.card);
if (CandyBarApplication.getConfiguration().getRequestStyle() == CandyBarApplication.Style.PORTRAIT_FLAT_LANDSCAPE_FLAT &&
card != null) {
if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
card.setRadius(0f);
card.setUseCompatPadding(false);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams();
params.setMargins(0, 0, margin, margin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
}
}
if (!Preferences.get(mContext).isCardShadowEnabled() && card != null) {
card.setCardElevation(0);
}
int padding = mContext.getResources().getDimensionPixelSize(R.dimen.content_margin) +
mContext.getResources().getDimensionPixelSize(R.dimen.icon_size_small);
content.setPadding(padding, 0, 0, 0);
container.setPadding(padding, 0, padding, 0);
int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary);
title.setCompoundDrawablesWithIntrinsicBounds(
DrawableHelper.getTintedDrawable(mContext,
R.drawable.ic_toolbar_premium_request, color),
null, null, null);
int primary = ColorHelper.getAttributeColor(mContext, R.attr.colorPrimary);
int accent = ColorHelper.getAttributeColor(mContext, R.attr.colorAccent);
button.setTextColor(ColorHelper.getTitleTextColor(primary));
progress.getProgressDrawable().setColorFilter(accent, PorterDuff.Mode.SRC_IN);
button.setOnClickListener(this);
}
/**
* 设置加载的dialog
*
* @param loadText String
*/
public void setProgress(String loadText) {
setType(DIALOG_PROGRESS);
View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_progress, null);
TextView tv_load = (TextView) view.findViewById(R.id.tv_load);
tv_load.setText(loadText);
showListOrEditView(view);
hideButtons();
hideTitle();
CardView cardView = (CardView) findViewById(R.id.card);
FrameLayout.LayoutParams params = (LayoutParams) cardView.getLayoutParams();
params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.CENTER;
cardView.setRadius(InputUtils.dp2px(getContext(),3));
cardView.setLayoutParams(params);
setFullBackgroundColor(Color.TRANSPARENT);
}