需要gridview android中所有大小相同的图片
我想在我的活动之一的gridview中显示用户发布的所有图片。这些是我的代码,我的结果如下图所示。我在gridview中指定了每个图片的宽度和高度(90dp,90dp),但没有这样做。它们被填充为上传的大小(横向/纵向)。此外,即使将gridview的高度设置为包裹内容,该高度仍与图片相同(约200dp may b)。我如何解决这个问题?我哪里做错了 每张图片的型号:需要gridview android中所有大小相同的图片,android,image,gridview,Android,Image,Gridview,我想在我的活动之一的gridview中显示用户发布的所有图片。这些是我的代码,我的结果如下图所示。我在gridview中指定了每个图片的宽度和高度(90dp,90dp),但没有这样做。它们被填充为上传的大小(横向/纵向)。此外,即使将gridview的高度设置为包裹内容,该高度仍与图片相同(约200dp may b)。我如何解决这个问题?我哪里做错了 每张图片的型号: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
app:srcCompat="@drawable/post2"
android:id="@+id/imageView2"
android:scaleType="centerCrop"
android:layout_margin="0dp"/>
</RelativeLayout>
我在另一个活动中的Gridview:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/content_competition_user"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.golstars.www.glostars.competitionUser"
tools:showIn="@layout/activity_competition_user">
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:numColumns="3"
android:verticalSpacing="8dp"
android:stretchMode="columnWidth"
android:horizontalSpacing="8dp"
android:id="@+id/competitionusergrid"
/>
</ScrollView>
我的适配器:
MyUser mUser = MyUser.getmUser();
mUser.setContext(this);
Picasso.with(this).load(mUser.getProfilePicURL()).into(profileFAB);
targetList = new ArrayList<>();
targetAdapter = new GridAdapter(getApplicationContext(), targetList);
competitionusergrid.setAdapter(targetAdapter);
String target = "";
target = this.getIntent().getStringExtra("LOAD_TARGET");
System.out.println(target);
if(target.equals("COMPETITION")){
//if we have competition pics
if(targetList.isEmpty()){
ArrayList<String> aux = this.getIntent().getStringArrayListExtra("COMPETITION_PICS");
System.out.println("target list - " + aux);
for(int i = 0; i < aux.size(); i++){
targetList.add(aux.get(i));
targetAdapter.notifyDataSetChanged();
}
}
MyUser mUser=MyUser.getmUser();
mUser.setContext(本);
将(mUser.getProfilePicURL())加载到(profileFAB)中;
targetList=newarraylist();
targetAdapter=新的GridAdapter(getApplicationContext(),targetList);
competitionusergrid.setAdapter(targetAdapter);
字符串target=“”;
target=this.getIntent().getStringExtra(“加载目标”);
系统输出打印项次(目标);
if(目标平等(“竞争”)){
//如果我们有竞争对手的照片
if(targetList.isEmpty()){
ArrayList aux=this.getIntent().getStringArrayListExtra(“竞争对手”);
System.out.println(“目标列表-”+aux);
对于(int i=0;i
外观:使用
RecyclerView
代替GridView
,RecyclerView与GridView相同,易于实现
使用宽度和高度相同的所有图像。如果要使用当前代码,则可以使用以下图像视图
public class SquareImageView extends ImageView {
public SquareImageView(Context context) {
super(context);
}
public SquareImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}}
以及每个项目的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/post2"
android:id="@+id/imageView2"
android:scaleType="centerCrop"
android:layout_margin="0dp"/>
</RelativeLayout>
您能分享一下UI图像的外观吗?@rahul抱歉忘了添加UI,我刚做了请检查。@shakilMahmudShanto您不需要使用RelativeLayout for your单视图“每张图片的模型”这是您在那里使用的一个额外的不必要视图。请仅使用ImageView,并查看这是否是导致问题的原因。因为您已将ImageView设置为90dp,但您的相对布局是match_parent。如果不起作用,请告诉我