package com.example.yjyyj.myapplication;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import java.util.List;
/**
* Created by yjyyj on 2018/4/8.
*/
public class ListAdapter
extends ArrayAdapter<bdlogo> {
int resource =
0;
private List<bdlogo>
strList;
public boolean flag=
false;
public ListAdapter(Context context,
int Id,List<bdlogo> objects){
super(context,Id,objects);
resource = Id;
strList = objects;
}
@Override
public View getView(
int position,View convertView,ViewGroup parent){
bdlogo bd = getItem(position);
View view = LayoutInflater.
from(getContext()).inflate(
resource,parent,
false);
ImageView image = (ImageView)view.findViewById(R.id.
bdimage);
TextView text = (TextView)view.findViewById(R.id.
textid);
image.setImageBitmap(bd.getimage());
text.setText(bd.gettext());
if(bd.getimage()!=
null) {
text.setHeight(bd.gethigh());
}
ViewGroup.MarginLayoutParams margin9 =
new ViewGroup.MarginLayoutParams(
image.getLayoutParams());
LinearLayout.LayoutParams layoutParams9 =
new LinearLayout.LayoutParams(margin9);
layoutParams9.
height = bd.gethigh();
//设置图片的高度
layoutParams9.
gravity = Gravity.
CENTER;
image.setLayoutParams(layoutParams9);
if(position%
2==
0) {
view.setBackgroundColor(Color.
BLUE);
}
else{
view.setBackgroundColor(Color.
YELLOW);
}
return view;
}
}