图片没有显示,应用程序正在启动,但没有图片显示,你能帮我解决吗?我猜Gridimage的问题。 plesae并不是毕加索的占位符没有在列表视图中显示。
public class GridViewAdapter extends ArrayAdapter<GridImages> {
private Context mContext;
private int layoutResourceId;
private ArrayList<GridImages> mGridImages = new ArrayList<GridImages>();
public GridViewAdapter(Context mContext, int layoutResourceId, ArrayList<GridImages> mGridImages) {
super(mContext, layoutResourceId, mGridImages);
this.layoutResourceId = layoutResourceId;
this.mContext = mContext;
this.mGridImages = mGridImages;
}
/**
* Updates grid data and refresh grid items.
* @param mGridData
*/
public void setGridData(ArrayList<GridImages> mGridImages) {
this.mGridImages = mGridImages;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null){
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
convertView = inflater.inflate(layoutResourceId, parent, false);
holder.imageView = (ImageView)convertView.findViewById(R.id.grid_item_image);
holder.titleTextView = (TextView)convertView.findViewById(R.id.grid_item_title);
convertView.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag();
}
String url = "http://www.justedhak.comlu.com/images/uploaded_images.jpg";
Picasso.with(mContext)
.load(url)
.placeholder(R.drawable.ic_launcher)
.error(R.drawable.ic_launcher)
.noFade().resize(150,150)
.centerCrop()
.into(holder.imageView);
return convertView;
}
static class ViewHolder {
TextView titleTextView;
ImageView imageView;
}
}
这是主要活动。
公共类MainActivity扩展了ActionBarActivity {
GridViewAdapter mGridAdapter;
private ArrayList<GridImages> mGridImages;
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list1);
mGridImages = new ArrayList<>();
mGridAdapter = new GridViewAdapter(this, R.layout.grid_item_layout, mGridImages);
listView.setAdapter(mGridAdapter);
}
活动主要
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.justedhak.MainActivity" >
<ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="100dp"
android:drawSelectorOnTop="true"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"
android:focusable="true"
android:clickable="true"/>
</RelativeLayout>
网格项目布局
<ImageView
android:id="@+id/grid_item_image"
android:layout_width="500dp"
android:layout_height="500dp"
/>
<TextView
android:id="@+id/grid_item_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:maxLines="2"
android:layout_below="@+id/grid_item_image"
android:ellipsize="marquee"
android:textSize="12sp" />
</RelativeLayout>
答案 0 :(得分:0)
检查一次布局。 尝试为图像视图设置特定高度并查看。
如果您没有成功添加布局代码。