package com.demo;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnTouchListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.TableLayout.LayoutParams;
import com.demo.ControlType.controltype;
public class FuListView extends View
implements OnTouchListener
,OnGestureListener
{
final String COL_WIDTH="width";
final String COL_NAME="colname";
final String GRAVITY="gravity";
final String CONTROL_TYPE="controltype";
final int MINID=1000;
final int ORIGINALCOLOR=Color.WHITE;
final int SELECTEDCOLOR=Color.BLUE;
final int LINECOLOR=Color.BLACK;//分隔线的颜色
final int TEXTCOLOR=Color.BLACK;//字的颜色
final int LINEWIDTH=1;//分隔线的默认宽度
final int COLMINWIDTH=10;//列最小宽度,防止把列拉没了
private GestureDetector mGestureDetector;
RadioGroup radioGroup=null;
static int screenWidth=0;
static int screenHeight=0;
private Activity activity;
private Line lineView;
// private Cursor cursor;
private List<HashMap<String,Object>> colList;
private List<HashMap<String,Object>> rowList;
private HashMap<String, Object> listViewProperty;
//action_down的时候坐标的x位置
//action_up的时候坐标的x位置,action_up-action_down等于鼠标在水平位置的位移
private int originalx=0;
public FuListView(List<HashMap<String,Object>> colList,
List<HashMap<String,Object>> rowList,
HashMap<String, Object> listViewProperty,
Activity activity
){
super(activity.getApplicationContext());
this.activity=activity;
this.colList=colList;
this.rowList=rowList;
this.listViewProperty=listViewProperty;
}
public View createFuListView(){
mGestureDetector=new GestureDetector(this);
// mGestureDetector.setIsLongpressEnabled(true);
//计算每行剩下的宽度,也就是最后一列的宽度
int iLeftWidth=getLeftWidth();
//所有数值行的Cell的params
LinearLayout.LayoutParams params =new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
ScrollView scrollView=new ScrollView(activity);
scrollView.setBackgroundColor(ORIGINALCOLOR);
scrollView.setLayoutParams(params);
scrollView.setVerticalScrollBarEnabled(true);
scrollView.setHorizontalScrollBarEnabled(true);
LinearLayout linearLayout=new LinearLayout(activity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setLayoutParams(params);
TableLayout table=new TableLayout(activity);
table.setLayoutParams(params);
//第一行,列头
TableRow tableRow=new TableRow(activity);
tableRow.setBackgroundColor(Color.GRAY);
LinearLayout line=new LinearLayout(activity);
tableRow.addView(line);
for(int i=0;i<colList.size();i++){
View view=createCell(0,i,iLeftWidth,1);
line.addView(view);
//画列分隔线
view=createCell(0,i,iLeftWidth,2);
line.addView(view);
}
table.addView(tableRow);
//数据行
for(int i=1;i<=rowList.size();i++){
tableRow=new TableRow(activity);
line=new LinearLayout(activity);
for(int j=0;j<colList.size();j++){
View view=createCell(i,j,iLeftWidth,0);
line.addView(view);
if(listViewProperty!=null
&& listViewProperty.get("bNeedVerticalLine").equals(new Boolean("true"))){
view=createCell(i,j,iLeftWidth,2);
line.addView(view);
}
}
tableRow.addView(line);
table.addView(tableRow);
if(listViewProperty!=null
&& listViewProperty.get("bNeedHorizonLine").equals(new Boolean("true"))){
//行分隔线
View lineV=new View(activity);
lineV.setBackgroundColor(LINECOLOR);
params=new LayoutParams();
params.height=1;
lineV.setLayoutParams(params);
table.addView(lineV);
}
}
linearLayout.addView(table);
scrollView.addView(linearLayout);
activity.setContentView(scrollView);
// cursor=new Cursor(activity);
// table.addView(cursor);
// cursor.setVisibility(View.INVISIBLE);
lineView=new Line(activity);
table.addView(lineView);
lineView.setVisibility(View.INVISIBLE);
return scrollView;
}
//选中数据行
ViewGroup tmpLinearLayout=null;
public boolean onTouch(View v, MotionEvent event) {
int iColIndex=v.getId()-MINID;//动作的触发是在列头的第几列
//是否列头
boolean bHeadLine=false;
if(v.getId()>MINID && v.getId()<MINID*2)
bHeadLine=true;
int x= new Float(event.getX()).intValue()+v.getLeft();
if(bHeadLine){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.i("tag","+++++++++++ACTION_DOWN++++++++++++++++++++");
originalx=x;
// cursor.setLocation(0,x-20);
// cursor.setVisibility(View.VISIBLE);
// cursor.invalidate();
lineView.x=x;
lineView.yHeight=((TableLayout)v.getParent().getParent().getParent()).getHeight();
lineView.setLocation(0, 0);
lineView.setVisibility(View.VISIBLE);
lineView.invalidate();
break;
case MotionEvent.ACTION_MOVE:
Log.i("tag","+++++++++++ACTION_MOVE++++++++++++++++++++");
//画线的横坐标的位置
lineView.x=x;
lineView.yHeight=((TableLayout)v.getParent().getParent().getParent()).getHeight();
lineView.invalidate();
// cursor.setLocation(0, x-20);
// cursor.invalidate();
// cursor.setVisibility(View.VISIBLE);
break;
case MotionEvent.ACTION_UP:
Log.i("tag","+++++++++++ACTION_UP++++++++++++++++++++");
int diff=x-originalx;
for(int i=0;i<rowList.size()+1;i++){
View tmpV=activity.findViewById(MINID*(i+1)+iColIndex);
if(tmpV.getLayoutParams().width+diff<0)
tmpV.getLayoutParams().width=COLMINWIDTH;
else
tmpV.getLayoutParams().width=tmpV.getLayoutParams().width+diff;
try {
((TextView)tmpV).setWidth(tmpV.getWidth()+diff);
} catch (Exception e) {
e.printStackTrace();
}
}
lineView.invalidate();
lineView.setVisibility(View.INVISIBLE);
// cursor.setVisibility(View.INVISIBLE);
break;
}
}
//是否数据行
boolean bIsDataRow=false;
if(v.getId()>MINID*2)
bIsDataRow=true;
if(bIsDataRow){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
tmpLinearLayout=(LinearLayout)v.getParent();
TableLayout tableLayout=(TableLayout)v.getParent().getParent().getParent();
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
FullListView.rar (38个子文件)
FullListView
.project 848B
default.properties 449B
bin
com
demo
FuListView$1.class 2KB
R$string.class 397B
MyProvider.class 6KB
R$layout.class 394B
Line.class 2KB
ControlType.class 359B
ControlType$controltype.class 1KB
MyDBHelper.class 1KB
R$drawable.class 370B
FuListView.class 14KB
R.class 461B
ItemEditor.class 3KB
FullListView.class 6KB
Cursor.class 560B
R$attr.class 310B
R$id.class 503B
ItemColumn.class 565B
FullListView.apk 22KB
resources.ap_ 7KB
classes.dex 28KB
AndroidManifest.xml 767B
src
com
demo
ItemColumn.java 434B
Cursor.java 657B
FullListView.java 9KB
MyProvider.java 5KB
FuListView.java 19KB
MyDBHelper.java 1KB
Line.java 2KB
ItemEditor.java 2KB
ControlType.java 164B
res
values
strings.xml 175B
layout
editor.xml 1KB
main.xml 382B
drawable
icon.png 3KB
.classpath 352B
gen
com
demo
R.java 1KB
assets
共 38 条
- 1
资源评论
- WELLTEN2013-11-27很不错,但是还有点小bug。
- Ending2013-11-26不错的资源,正好可以学习参考下。
- llaomao2012-07-23学习下,刚好自己在写通话记录的显示
- austzyf2013-08-30对我很有帮助!谢谢分享
lorrenji
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功