我创建了一个具有线性布局的自定义适配器,并且我正在尝试向其动态添加一些图像。除最后一张外,所有图像都成功插入。Android:向LinearLayout添加多个图像时,最后一个图像不出现
编辑︰最后一个图像被添加到LinearLayout但它不会出于某种原因!
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater myCustomInflater = LayoutInflater.from(getContext());
View customView = myCustomInflater.inflate(R.layout.custom_row, parent, false);
LinearLayout rowWordLayout =(LinearLayout) customView.findViewById(R.id.rowWordID);
String singleWord = getItem(position);
String[] characters = singleWord.split("-");
for(int i=0; i<characters.length; i++){
String symbol = characters[i];
ImageView image = new ImageView(getApplicationContext());
image.setImageResource(getResources().getIdentifier(symbol, "drawable", getPackageName()));
image.setLayoutParams(new android.view.ViewGroup.LayoutParams(80,60));
image.setMaxHeight(20);
image.setMaxWidth(20);
image.setClickable(false);
rowWordLayout.addView(image);
}
}
我试了60和wrap_content,但它没有工作:( –
我有另一个问题。这是我的错误。谢谢 –