我的问题是我有一些包含图像和文本的帖子列表适配器,当我向下滚动加载图像并且一切正常时,单元格的高度会根据图像高度动态变化,但是当我向上滚动图像时,再次加载,布局开始扭曲,如GIF图片所示
XML文件
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/roundborder"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/top_card_view"
app:cardCornerRadius="8dp">
<ImageView
android:id="@+id/post_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="@+id/speech_bubble"
android:layout_marginLeft="5dp"
android:src="@drawable/ic_location"
android:visibility="invisible"
android:layout_marginBottom="5dp"
android:layout_gravity="bottom"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:text=""
android:layout_toRightOf="@+id/speech_bubble"
android:layout_marginLeft="26dp"
android:id="@+id/location"
android:background="@drawable/roundborder_gray"
android:textColor="@color/white"
android:layout_marginBottom="7dp"
android:layout_gravity="bottom"
android:visibility="invisible"
/>
</android.support.v7.widget.CardView>
<Button
android:id="@+id/delete"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_delete"
android:visibility="visible"
android:layout_alignParentRight="true"
android:elevation="2dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@id/relLayout2"
android:layout_below="@+id/top_card_view"
android:background="@color/white"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="@+id/whois"
android:layout_centerVertical="true">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/profile_photo"
app:civ_border_color="@color/black"
app:civ_border_width="0.5dp"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text=""
android:layout_toRightOf="@+id/profile_photo"
android:layout_marginLeft="10dp"
android:textStyle="bold"
android:layout_centerVertical="true"
android:id="@+id/username"
android:textColor="@color/black"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="45dp"
android:layout_height="match_parent"
android:id="@+id/heartLayout"
android:layout_alignParentRight="true"
android:background="@color/white">
<ImageView
android:id="@+id/image_heart_red"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_heart_red"
android:visibility="visible"/>
<ImageView
android:id="@+id/image_heart"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_heart_white"
android:visibility="visible" />
<RelativeLayout
android:id="@+id/heart_click"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="visible" />
</RelativeLayout>
<TextView
android:id="@+id/image_likes"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/heartLayout"
android:paddingRight="0dp"
android:text=""
android:textColor="@color/black"
android:textSize="15sp"
android:textStyle="bold"
android:textAlignment="viewEnd"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/relLayout3"
android:layout_below="@+id/relLayout2"
android:paddingHorizontal="10dp"
android:background="@color/white">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/grey"
android:textSize="12sp"
android:id="@+id/image_time_posted"
android:layout_marginBottom="5dp"
android:paddingTop="0dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="15sp"
android:id="@+id/image_caption"
android:layout_marginTop="-3dp"
android:layout_marginBottom="5dp"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
代码
public class MainfeedListAdapter extends ArrayAdapter<Photo> {
public interface OnLoadMoreItemsListener{
void onLoadMoreItems();
}
OnLoadMoreItemsListener mOnLoadMoreItemsListener;
private static final String TAG = "MainfeedListAdapter";
private LayoutInflater mInflater;
private int mLayoutResource;
private Context mContext;
private String currentUsername = "";
private String photo_uid, user_uid;
public MainfeedListAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<Photo> objects) {
super(context, resource, objects);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mLayoutResource = resource;
this.mContext = context;
}
class ViewHolder{
CircleImageView mprofileImage;
String likesString;
TextView username, timeDetla, caption, location, lastdaynum, likes, comments;
ImageView image;
ImageView heartRed, heartWhite, comment;
Button delete;
RelativeLayout mRellay, mRellay2, RellayHeart;
UserAccountSettings settings = new UserAccountSettings();
User user = new User();
StringBuilder users;
String mLikesString;
boolean likeByCurrentUser;
Heart heart;
GestureDetector detector;
Photo photo;
}
@NonNull
@Override
public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
final ViewHolder holder;
if(convertView == null){
convertView = mInflater.inflate(mLayoutResource, parent, false);
holder = new ViewHolder();
holder.username = (TextView) convertView.findViewById(R.id.username);
holder.image = (ImageView) convertView.findViewById(R.id.post_image);
holder.heartRed = (ImageView) convertView.findViewById(R.id.image_heart_red);
holder.heartWhite = (ImageView) convertView.findViewById(R.id.image_heart);
holder.comment = (ImageView) convertView.findViewById(R.id.speech_bubble);
holder.likes = (TextView) convertView.findViewById(R.id.image_likes);
holder.caption = (TextView) convertView.findViewById(R.id.image_caption);
holder.location = (TextView) convertView.findViewById(R.id.location);
holder.timeDetla = (TextView) convertView.findViewById(R.id.image_time_posted);
holder.mprofileImage = (CircleImageView) convertView.findViewById(R.id.profile_photo);
holder.mRellay = (RelativeLayout) convertView.findViewById(R.id.whois);
holder.mRellay2 = (RelativeLayout) convertView.findViewById(R.id.relLayout3);
holder.RellayHeart = (RelativeLayout) convertView.findViewById(R.id.heart_click);
holder.heart = new Heart(holder.heartWhite, holder.heartRed);
holder.photo = getItem(position);
holder.detector = new GestureDetector(mContext, new GestureListener(holder));
holder.users = new StringBuilder();
holder.delete = (Button) convertView.findViewById(R.id.delete);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
holder.mprofileImage.setImageBitmap(null);
holder.image.setImageBitmap(null);
}
我想已经加载了帖子以解决它们的问题,当我向上滚动它们以加载图片时