在用ListView做表格时我想大家都遇到和我一样的问题如图

 

解决这个问题大部都会想到动态设置控件宽度,继承 SimpleAdapter 重写 public View getView(int position,View convertView,ViewGroup parent)方法,代码如下:

 

package com.TableTest; import java.util.List; import java.util.Map; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.SimpleAdapter; public class TableAdapter extends SimpleAdapter { private int screenWidth;//屏幕宽度 public int getScreenWidth() { return screenWidth; } public void setScreenWidth(int screenWidth) { this.screenWidth = screenWidth; } public TableAdapter(Context context, List<? extends Map> data,int resource, String[] from, int[] to) { super(context, data, resource, from, to); } public View getView(int position,View convertView,ViewGroup parent){ int itemWidth = (screenWidth - 10) / 3; View view = super.getView(position,convertView,parent); View table_item_item0 = view.findViewById(R.id.table_item_item0); View table_item_item1 = view.findViewById(R.id.table_item_item1); View table_item_item2 = view.findViewById(R.id.table_item_item2); LinearLayout.LayoutParams linearParams0 = (LinearLayout.LayoutParams)table_item_item0.getLayoutParams(); linearParams0.width = itemWidth; table_item_item0.setLayoutParams(linearParams0); LinearLayout.LayoutParams linearParams1 = (LinearLayout.LayoutParams)table_item_item1.getLayoutParams(); linearParams1.width = itemWidth; table_item_item1.setLayoutParams(linearParams1); LinearLayout.LayoutParams linearParams2 = (LinearLayout.LayoutParams)table_item_item2.getLayoutParams(); linearParams2.width = itemWidth; table_item_item2.setLayoutParams(linearParams2); return view; } }  

 

效果如图

 

工程完整代码下载地址:http://download.csdn.net/source/3409570

 

 

 

解决上列问题还有一个更简单的方法 就是把 表格里的控件设置一个超长值如 android:layout_width="1000px" 

代码如下

<?xml version="1.0" encoding="utf-8"?>  

工程完整代码下载地址:http://download.csdn.net/source/3409613

 

更多相关文章

  1. Android(安卓)拖动条(SeekBar)实例 附完整demo项目代码
  2. Android手势研究(textview及listview对比验证)(二)
  3. 我在android C层犯的错误
  4. 定制android通知(Notification)
  5. android:transcriptMode用法
  6. Android(4.Activity的基本控件)
  7. AutoCompleteTextView 无限制输入字符及获得焦点时显示
  8. 自定义Android,toast,以及多线程toast
  9. Android通过泛型来简化findViewById

随机推荐

  1. Android(安卓)training
  2. Android之UtilsRequesServicetHelp工具类
  3. Android图片按比例缩放
  4. Android(安卓)同步请求导致系统崩溃andro
  5. android aidl service
  6. android 获取另一个apk的信息
  7. Android(安卓)Studio中使用Git报:Git Una
  8. android studio debug framework
  9. Android中Radio单选按钮操作
  10. Android之通过category跳转到指定的Activ