android listView 第一列为什么不能居中

ghostgoodbye 2012-03-13 05:13:42
在我的listView中除了第一行是居中的,其余的怎么不能居中啊 谢谢 拉
...全文
523 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ghostgoodbye 2012-03-13
  • 打赏
  • 举报
回复
我的是创建了一个对象 具体代码是:
BaseAdapter ba_detail=new BaseAdapter()//新建适配器
{

@Override
public int getCount()
{
return 5;//得到列表的长度
}
@Override
public Object getItem(int arg0){return null;}
@Override
public long getItemId(int arg0){return 0;}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2)//为每一项添加内容
{
LinearLayout ll_detail=new LinearLayout(sprinkler_detail_infomation.this);
ll_detail.setOrientation(LinearLayout.HORIZONTAL); //设置朝向
ll_detail.setPadding(5,5,5,5);
ll_detail.setGravity(Gravity.CENTER);//四周留白

TextView tv1=new TextView(sprinkler_detail_infomation.this);
tv1.setWidth(50);
tv1.setHeight(50);
tv1.setGravity(Gravity.CENTER);
tv1.setText(gNameAndgDetail[arg0*10+(modify_number-1)*50]);
tv1.setTextColor(getResources().getColor(R.color.text_color));
ll_detail.addView(tv1);
TextView tv2=new TextView(sprinkler_detail_infomation.this);
tv2.setWidth(72);
tv2.setHeight(50);
tv2.setGravity(Gravity.CENTER);
tv2.setText(gNameAndgDetail[arg0*10+(modify_number-1)*50+1]);
tv2.setTextColor(getResources().getColor(R.color.text_color));
ll_detail.addView(tv2);

TextView tv3=new TextView(sprinkler_detail_infomation.this);
tv3.setWidth(123);
tv3.setHeight(50);
tv3.setGravity(Gravity.CENTER);
tv3.setText(gNameAndgDetail[arg0*10+(modify_number-1)*50+2]);
tv3.setTextColor(getResources().getColor(R.color.text_color));
ll_detail.addView(tv3);

TextView tv4=new TextView(sprinkler_detail_infomation.this);
tv4.setWidth(85);
tv4.setHeight(50);
tv4.setGravity(Gravity.CENTER);
tv4.setText(gNameAndgDetail[arg0*10+(modify_number-1)*50+3]);
tv4.setTextColor(getResources().getColor(R.color.text_color));
ll_detail.addView(tv4);

TextView tv5=new TextView(sprinkler_detail_infomation.this);
tv5.setWidth(55);
tv5.setHeight(50);
tv5.setGravity(Gravity.CENTER);
tv5.setText(gNameAndgDetail[arg0*10+(modify_number-1)*50+4]);
tv5.setTextColor(getResources().getColor(R.color.text_color));
ll_detail.addView(tv5);

TextView tv6=new TextView(sprinkler_detail_infomation.this);
tv6.setWidth(85);
tv6.setHeight(50);
tv6.setGravity(Gravity.CENTER);
tv6.setText(gNameAndgDetail[arg0*10+(modify_number-1)*50+5]);
tv6.setTextColor(getResources().getColor(R.color.text_color));
ll_detail.addView(tv6);

TextView tv7=new TextView(sprinkler_detail_infomation.this);
tv7.setWidth(85);
tv7.setHeight(50);
tv7.setGravity(Gravity.CENTER);
tv7.setText(gNameAndgDetail[arg0*10+(modify_number-1)*50+6]);
tv7.setTextColor(getResources().getColor(R.color.text_color));
ll_detail.addView(tv7);

TextView tv8=new TextView(sprinkler_detail_infomation.this);
tv8.setWidth(85);
tv8.setHeight(50);
tv8.setGravity(Gravity.CENTER);
tv8.setText(gNameAndgDetail[arg0*10+(modify_number-1)*50+7]);
tv8.setTextColor(getResources().getColor(R.color.text_color));
ll_detail.addView(tv8);

TextView tv9=new TextView(sprinkler_detail_infomation.this);
tv9.setWidth(85);
tv9.setHeight(50);
tv9.setGravity(Gravity.CENTER);
tv9.setText(gNameAndgDetail[arg0*10+(modify_number-1)*50+8]);
tv9.setTextColor(getResources().getColor(R.color.text_color));
ll_detail.addView(tv9);

TextView tv10=new TextView(sprinkler_detail_infomation.this);
tv10.setWidth(85);
tv10.setHeight(50);
tv10.setGravity(Gravity.CENTER);
tv10.setText(gNameAndgDetail[arg0*10+(modify_number-1)*50+9]);
tv10.setTextColor(getResources().getColor(R.color.text_color));
ll_detail.addView(tv10);
return ll_detail;//将此LinearLayout返回
}
};
pby_bob 2012-03-13
  • 打赏
  • 举报
回复
楼主这个问题提的太初略了,能不能再详细点,是继承了什么adapter?

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧