Skip to content

Commit 4e3cc33

Browse files
committed
表格制作
1 parent f2a6c43 commit 4e3cc33

30 files changed

Lines changed: 898 additions & 0 deletions

‎MakeTable/.gitignore‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures

‎MakeTable/app/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

‎MakeTable/app/build.gradle‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 22
5+
buildToolsVersion "22.0.0"
6+
7+
defaultConfig {
8+
applicationId "com.lyl.maketable"
9+
minSdkVersion 15
10+
targetSdkVersion 22
11+
versionCode 1
12+
versionName "1.0.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
testCompile 'junit:junit:4.12'
25+
compile 'com.android.support:appcompat-v7:22.0.0'
26+
}

‎MakeTable/app/proguard-rules.pro‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in D:\Android\android-sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.lyl.maketable;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.lyl.maketable" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme" >
11+
<activity android:name=".MainActivity" >
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN" />
14+
15+
<category android:name="android.intent.category.LAUNCHER" />
16+
</intent-filter>
17+
</activity>
18+
</application>
19+
20+
</manifest>
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package com.lyl.maketable;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.BaseAdapter;
9+
import android.widget.LinearLayout;
10+
import android.widget.TextView;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
public class MainActivity extends Activity {
16+
17+
private NoscrollListView mLeft;
18+
private LeftAdapter mLeftAdapter;
19+
20+
private NoscrollListView mData;
21+
private DataAdapter mDataAdapter;
22+
23+
private SyncHorizontalScrollView mHeaderHorizontal;
24+
private SyncHorizontalScrollView mDataHorizontal;
25+
26+
private List<String> mListData;
27+
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
setContentView(R.layout.activity_main);
32+
33+
initView();
34+
}
35+
36+
private void initView(){
37+
mLeft = (NoscrollListView) findViewById(R.id.lv_left);
38+
mData = (NoscrollListView) findViewById(R.id.lv_data);
39+
mDataHorizontal = (SyncHorizontalScrollView) findViewById(R.id.data_horizontal);
40+
mHeaderHorizontal = (SyncHorizontalScrollView) findViewById(R.id.header_horizontal);
41+
42+
mDataHorizontal.setScrollView(mHeaderHorizontal);
43+
mHeaderHorizontal.setScrollView(mDataHorizontal);
44+
45+
mListData = new ArrayList<>();
46+
mListData.add("1");
47+
mListData.add("2");
48+
mListData.add("3");
49+
mListData.add("4");
50+
mListData.add("5");
51+
mListData.add("6");
52+
mListData.add("7");
53+
mListData.add("8");
54+
mListData.add("9");
55+
mListData.add("10");
56+
mListData.add("11");
57+
mListData.add("12");
58+
mListData.add("13");
59+
60+
mLeftAdapter= new LeftAdapter();
61+
mLeft.setAdapter(mLeftAdapter);
62+
63+
mDataAdapter = new DataAdapter();
64+
mData.setAdapter(mDataAdapter);
65+
}
66+
67+
class LeftAdapter extends BaseAdapter {
68+
69+
@Override
70+
public int getCount() {
71+
return mListData.size();
72+
}
73+
74+
@Override
75+
public Object getItem(int position) {
76+
return mListData.get(position);
77+
}
78+
79+
@Override
80+
public long getItemId(int position) {
81+
return position;
82+
}
83+
84+
@Override
85+
public View getView(int position, View convertView, ViewGroup parent) {
86+
ViewHolder holder = null;
87+
if (convertView == null) {
88+
holder = new ViewHolder();
89+
convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.tv_left, null);
90+
holder.tvLeft = (TextView) convertView.findViewById(R.id.tv_left);
91+
convertView.setTag(holder);
92+
} else {
93+
holder = (ViewHolder) convertView.getTag();
94+
}
95+
96+
holder.tvLeft.setText("第" + position + "行");
97+
98+
return convertView;
99+
}
100+
101+
class ViewHolder {
102+
TextView tvLeft;
103+
}
104+
}
105+
106+
class DataAdapter extends BaseAdapter {
107+
108+
@Override
109+
public int getCount() {
110+
return mListData.size();
111+
}
112+
113+
@Override
114+
public Object getItem(int position) {
115+
return mListData.get(position);
116+
}
117+
118+
@Override
119+
public long getItemId(int position) {
120+
return position;
121+
}
122+
123+
@Override
124+
public View getView(int position, View convertView, ViewGroup parent) {
125+
ViewHolder holder = null;
126+
if(convertView == null){
127+
holder = new ViewHolder();
128+
convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.item_data, null);
129+
holder.tvData = (TextView) convertView.findViewById(R.id.tv_data);
130+
holder.linContent = (LinearLayout) convertView.findViewById(R.id.lin_content);
131+
convertView.setTag(holder);
132+
}else{
133+
holder = (ViewHolder) convertView.getTag();
134+
}
135+
136+
return convertView;
137+
}
138+
139+
class ViewHolder {
140+
TextView tvData;
141+
LinearLayout linContent;
142+
}
143+
}
144+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.lyl.maketable;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
import android.widget.ListView;
6+
7+
/**
8+
* Wing_Li
9+
* 2016/12/2.
10+
*/
11+
public class NoscrollListView extends ListView {
12+
13+
public NoscrollListView(Context context) {
14+
super(context);
15+
}
16+
17+
public NoscrollListView(Context context, AttributeSet attrs) {
18+
super(context, attrs);
19+
}
20+
21+
public NoscrollListView(Context context, AttributeSet attrs, int defStyleAttr) {
22+
super(context, attrs, defStyleAttr);
23+
}
24+
25+
@Override
26+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
27+
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
28+
super.onMeasure(widthMeasureSpec, expandSpec);
29+
}
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.lyl.maketable;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
import android.view.View;
6+
import android.widget.HorizontalScrollView;
7+
8+
/**
9+
* Wing_Li
10+
* 2016/12/2.
11+
*/
12+
public class SyncHorizontalScrollView extends HorizontalScrollView {
13+
private View mView;
14+
15+
public SyncHorizontalScrollView(Context context) {
16+
super(context);
17+
}
18+
19+
public SyncHorizontalScrollView(Context context, AttributeSet attrs) {
20+
super(context, attrs);
21+
}
22+
23+
public SyncHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
24+
super(context, attrs, defStyleAttr);
25+
}
26+
27+
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
28+
super.onScrollChanged(l, t, oldl, oldt);
29+
if (mView != null) {
30+
mView.scrollTo(l, t);
31+
}
32+
}
33+
34+
public void setScrollView(View view) {
35+
mView = view;
36+
}
37+
}

0 commit comments

Comments
 (0)