我正在使用draggable gridview
,我必须在gridview中以编程方式添加子视图,我尝试了addView()
方法和其他Draw(Canvas)
方法来添加,但它不起作用。
请帮助我,如何添加subview
每个view
.draggable grid view
String color ="null";
try
{
word=inCartSongTitleList.get(i).toString();
color=inCartColor_List.get(i).toString();
time="00.00";
if(word.equals("null"))
{
word="";
}
}
catch(Exception e)
{
word="ERROR";
Log.e("",""+e+"");
}
//ImageView view = new ImageView(CartActivity.this);
LinearLayout view = new LinearLayout(CartActivity.this);
LinearLayout.LayoutParams trparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(trparams);
TextView txt=new TextView(CartActivity.this);
txt.setText("Mikin");
txt.setTextColor(Color.parseColor("#ffffff"));
Canvas canvas = new Canvas();
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText("Mikin",50,50,paint);
//ImageView view = new ImageView(CartActivity.this);
//view.setBackgroundResource(R.drawable.sound);
view.draw(canvas);
//view.setBackgroundColor(Color.parseColor("#ffffff"));
if(String.valueOf(color).equals("0"))
{
//view.setBackgroundColor(Color.parseColor("#768CA7"));
view.setBackgroundColor(Color.parseColor("#768CA7"));
//view.setImageBitmap(getThumb(word,"#768CA7",time));
}
else if(color.equals("null"))
{
view.setBackgroundColor(Color.parseColor("#768CA7"));
//imageView.setBackgroundColor(Color.parseColor("#768CA7"));
//view.setImageBitmap(getThumb(word,"#768CA7",time));
}
else if(color!=null)
{
view.setBackgroundColor(Color.parseColor(color));
//imageView.setBackgroundColor(Color.parseColor(color));
//view.setImageBitmap(getThumb(word,color,time));
}
//view.addView(imageView);
draggableGrid.addView(view);