这期内容当中小编将会给大家带来有关在android中使用GridView实现一个查看更多功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
首先来看一下效果图;
代码:
<LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@color/white" android:orientation="vertical"> <GridView android:id="@+id/grid_member" android:layout_width="match_parent" android:layout_height="0dp" android:layout_margin="15dp" android:layout_weight="1" android:horizontalSpacing="15dp" android:numColumns="5" android:verticalSpacing="15dp"></GridView> <LinearLayout android:id="@+id/llayout_look_more" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/btn_white_selector" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:drawableRight="@mipmap/arrow_down_qun" android:gravity="center" android:paddingBottom="30dp" android:paddingTop="15dp" android:text="查看更多群成员 " android:textSize="@dimen/small_middle_text_size" /> </LinearLayout> </LinearLayout>
然后是activity中部分判断的核心代码:
首先第一次判断和加载
if (mListData.size() > 15) { mGroupManageAdapter.setNumber(false); mLlayoutLookMore.setVisibility(View.VISIBLE); } else { mGroupManageAdapter.setNumber(true); mLlayoutLookMore.setVisibility(View.GONE); } mGroupManageAdapter.replace(mListData);
点击按钮之后的代码:
mGroupManageAdapter.setNumber(true); mLlayoutLookMore.setVisibility(View.GONE); mGroupManageAdapter.replace(mListData);
再贴上我的adapter部分代码:
public class GroupManageAdapter extends BaseAdapter { private Context mContext; private List<PublicEntity> mList = new ArrayList<>(); private boolean mListType = true;//是否显示全部成员,默认显示 public void setNumber(boolean mListType) { this.mListType = mListType; } public GroupManageAdapter(Context mContext) { this.mContext = mContext; } public void replace(List<PublicEntity> itemDataTypes) { mList.clear(); if (itemDataTypes.size() > 0) { mList.addAll(itemDataTypes); notifyDataSetChanged(); } } @Override public int getCount() { return mListType ? mList.size() : 15; } @Override public Object getItem(int position) { return mList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { convertView = View.inflate(mContext, R.layout.item_group_manage_head, null); holder = new ViewHolder(convertView); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } String mPic = mList.get(position).getTextOne(); if (mPic != null && mPic.length() > 0) { Picasso.with(mContext).load(mPic) .placeholder(R.mipmap.s_hearder_user_nor) .error(R.mipmap.s_hearder_user_nor) .transform(new CircleTransform()).into(holder.mImgHead); } else { holder.mImgHead.setImageResource(R.mipmap.s_hearder_user_nor); } //这里是删除成员的标记,不管。 if (mList.get(position).ismIsShowDeleteIcon()) { holder.mImgIconDelete.setVisibility(View.VISIBLE); } else { holder.mImgIconDelete.setVisibility(View.GONE); } holder.mTvName.setText(mList.get(position).getText()); return convertView; } static class ViewHolder { @BindView(R.id.img_head) ImageView mImgHead; @BindView(R.id.img_icon_delete) ImageView mImgIconDelete; @BindView(R.id.tv_name) TextView mTvName; ViewHolder(View view) { ButterKnife.bind(this, view); } } }
上述就是小编为大家分享的在android中使用GridView实现一个查看更多功能了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。