android中一行中有不一样颜色的字怎么显示,换行后且必须和上一行的第一个字对齐?? 5
1个回答
展开全部
您好,我的代码如下:
public static class DragListAdapter extends ArrayAdapter<String>{
public DragListAdapter(Context context, List<String> objects) {
super(context, 0, objects);
}
public List<String> getList(){
return list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item, null);
TextView textView = (TextView)view.findViewById(R.id.drag_list_item_text);
textView.setText(getItem(position));
switch(position){
case 0:
textView.setBackgroundResource(R.drawable.gray);
break;
case 1:
textView.setBackgroundResource(R.drawable.white);
break;
case 2:
textView.setBackgroundResource(R.drawable.Pink);
break;
case 3:
textView.setBackgroundResource(R.drawable.Cyan);
break;
case 4:
textView.setBackgroundResource(R.drawable.Gainsboro);
break;
case 5:
textView.setBackgroundResource(R.drawable.Magenta);
break;
case 6:
textView.setBackgroundResource(R.drawable.MediumSpringGreen);
break;
case 7:
textView.setBackgroundResource(R.drawable.SteelBlue);
break;
case 8:
textView.setBackgroundResource(R.drawable.Yellow);
break;
case 9:
textView.setBackgroundResource(R.drawable.LightSteelBlue);
break;
}
return view;
}
public static class DragListAdapter extends ArrayAdapter<String>{
public DragListAdapter(Context context, List<String> objects) {
super(context, 0, objects);
}
public List<String> getList(){
return list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item, null);
TextView textView = (TextView)view.findViewById(R.id.drag_list_item_text);
textView.setText(getItem(position));
switch(position){
case 0:
textView.setBackgroundResource(R.drawable.gray);
break;
case 1:
textView.setBackgroundResource(R.drawable.white);
break;
case 2:
textView.setBackgroundResource(R.drawable.Pink);
break;
case 3:
textView.setBackgroundResource(R.drawable.Cyan);
break;
case 4:
textView.setBackgroundResource(R.drawable.Gainsboro);
break;
case 5:
textView.setBackgroundResource(R.drawable.Magenta);
break;
case 6:
textView.setBackgroundResource(R.drawable.MediumSpringGreen);
break;
case 7:
textView.setBackgroundResource(R.drawable.SteelBlue);
break;
case 8:
textView.setBackgroundResource(R.drawable.Yellow);
break;
case 9:
textView.setBackgroundResource(R.drawable.LightSteelBlue);
break;
}
return view;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询