社区
Android
帖子详情
android listView 第一列为什么不能居中
ghostgoodbye
2012-03-13 05:13:42
在我的listView中除了第一行是居中的,其余的怎么不能居中啊 谢谢 拉
...全文
568
2
打赏
收藏
android listView 第一列为什么不能居中
在我的listView中除了第一行是居中的,其余的怎么不能居中啊 谢谢 拉
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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?
android
listview
居中
,在
ListView
中
居中
布局(示例代码)
在
Android
中,要使
ListView
内容
居中
,可以修改
ListView
及其列表项的布局。将
ListView
的宽度设置为match_parent,并在列表项的根布局中设置gravity为center。这样可以确保每个列表项整体
居中
显示。
Android
Studio中,让
listView
的每个Item
居中
本文介绍如何在
Android
开发中,通过自定义ArrayAdapter并重写getView()方法,将
ListView
中的每一项(Item)设置为
居中
对齐,从而实现美观的界面布局效果。
ListView
item布局
不能
居中
问题
本文分享了在项目开发过程中解决
ListView
Item内的TextView无法垂直
居中
的问题经验。通过使用
android
:layout_centerVertical=true属性成功实现了TextView的垂直
居中
显示。
[
android
]ListItem 中的内容垂直
居中
ListView
本文介绍如何在
Android
的
ListView
中实现ListItem的内容垂直
居中
。通过修改
ListView
的布局,将标题和副标题放入两个TextView并设置相应属性,可以达到预期效果。
调试记录:解决
listview
第一列
不
居中
的问题
本文探讨了在
Android
开发中,
ListView
与TextView布局不匹配的问题,并提供了调整布局以确保
第一列
与文本对齐的解决方案。
Android
80,490
社区成员
91,379
社区内容
发帖
与我相关
我的任务
Android
移动平台 Android
复制链接
扫一扫
分享
社区描述
移动平台 Android
android
android-studio
androidx
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章