【发布时间】:2020-04-24 22:01:59
【问题描述】:
我正在从 firebase firestore 集合中检索图像到网格图像视图中。但我只想显示具有当前用户 ID 的图像,并通过将可见性设置为消失来隐藏其余图像,但这会通过在图像之间留下空白(白色)空间来混淆视图。
这是我试图在我的适配器中隐藏视图
if (convertView == null)
convertView = inflater.inflate(R.layout.image_grid_view, null);
ImageView postImage = convertView.findViewById(R.id.my_store_posts);
Posts e = new Posts();
e = postList.get(position);
//final String title = e.getTitle();
final String image = e.getImage_url();
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
if (e.getUser_id().equals(uid)) {
Picasso.with(context).load(image).into(postImage);
}else {
postImage.setVisibility(View.GONE);
}
return convertView;
}
}
这是我的布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyStoreActivity">
<GridView
android:id="@+id/my_store_grid"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:numColumns="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
/>
适配器布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/my_store_posts"
android:layout_width="150dp"
android:layout_height="150dp"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/default_avatar" />
【问题讨论】:
标签: android gridview google-cloud-firestore