我在Android上的列表視圖中滾動圖像(延遲加載)上傳重複前兩個。 照片是從一個在線服務器上傳 另外,在Android 4.4上,照片非常大。 爲什麼?解決方案?從列表中的服務器重複列表視圖圖像
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
Log.d(TAG, "POS: " + position);
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.row_posts, parent, false);
holder = new ViewHolder();
holder.tvTitolo = (TextView) convertView.findViewById(R.id.tvTitoloPost);
holder.tvData = (TextView) convertView.findViewById(R.id.tvData);
holder.ivPost = (ImageView) convertView.findViewById(R.id.ivPost);
holder.tvContent = (TextView) convertView.findViewById(R.id.tvContent);
holder.tvExcerpt = (TextView) convertView.findViewById(R.id.tvExcerpt);
holder.wvPost = (WebView) convertView.findViewById(R.id.wvPost);
holder.tvIDPost = (TextView) convertView.findViewById(R.id.tvIDPost);
holder.tvUrlPost = (TextView)convertView.findViewById(R.id.tvURLPost);
holder.tvCommPost = (TextView)convertView.findViewById(R.id.tvCommPost);
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}final Post post = getItem(position);
holder.tvTitolo.setText(post.getTitle());
holder.tvData.setText(post.getDate());
WebSettings webSettings = holder.wvPost.getSettings();
webSettings.setBuiltInZoomControls(false);
webSettings.setUseWideViewPort(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setLightTouchEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setLoadWithOverviewMode(true);
holder.wvPost.setFocusable(false);
holder.wvPost.setClickable(false);
holder.wvPost.setFocusableInTouchMode(false);
holder.wvPost.setLongClickable(false);
holder.wvPost.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
holder.wvPost.loadUrl(post.getThumbnail());
Log.v(TAG, "html: <!DOCTYPE html><html><body style = \"text-align:center\"><img src= " + post.getThumbnail() + " alt=\"\"></body></html>");
holder.wvPost.loadDataWithBaseURL(null,"<!DOCTYPE html><html><body style = \"text-align:center\"><img src= " + post.getThumbnail() + " alt=\"\"></body></html>","text/html", "UTF-8", null);
holder.wvPost.setClickable(false);
if (post.getThumbnail().equals("null")) {
imageLoader.displayImage(null, holder.ivPost);
}else {
imageLoader.displayImage(post.getThumbnail(), holder.ivPost);
}
Log.d(TAG, "THUMB: " + post.getThumbnail());
/* if(post.getThumbnail().equals("null")){
holder.ivPost.setVisibility(View.GONE);
}else{
imageLoader.displayImage(post.getThumbnail(), holder.ivPost);
holder.ivPost.setVisibility(View.VISIBLE);
}*/
imageLoader.displayImage(post.getThumbnail(), holder.ivPost);
holder.tvExcerpt.setText(post.getExcerpt());
holder.tvContent.setText(post.getContent());
holder.tvIDPost.setText(post.getId());
holder.tvUrlPost.setText(post.getThumbnail());
String comments = "";
for (int i = 0; i < post.getmComments().size(); i++) {
comments = "<b>" + post.getmComments().get(i).getName() +
"</b><br>" +
post.getmComments().get(i).getContent() +
"<br><b>on </b>" +
post.getmComments().get(i).getDate() +
"<br><br>";
}
holder.tvCommPost.setText(comments);
return convertView;
}}
XML row_post:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="#ffffff" >
<TextView
android:id="@+id/tvTitoloPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Titolo"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvTitoloPost"
android:layout_below="@+id/tvTitoloPost"
android:text="Data" />
<WebView
android:id="@+id/wvPost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvData"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
/>
<ImageView
android:id="@+id/ivPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvData"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/default_avatar"
android:visibility="gone" />
<TextView
android:id="@+id/tvExcerpt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/wvPost"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:text="TextView" />
<TextView
android:id="@+id/tvContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/wvPost"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:maxLines="4"
android:text="TextView"
android:visibility="gone" />
<TextView
android:id="@+id/tvIDPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvContent"
android:layout_below="@+id/tvContent"
android:text="TextView"
android:visibility="gone" />
<TextView
android:id="@+id/tvURLPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvIDPost"
android:layout_below="@+id/tvContent"
android:text="TextView"
android:visibility="gone" />
<TextView
android:id="@+id/tvCommPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvURLPost"
android:layout_below="@+id/tvContent"
android:text="TextView"
android:visibility="gone" />
</RelativeLayout>
分享R.layout.row_posts。 –
row_post.xml已上架 – DevOkAnd