Skip to content

Commit 4e7cf2f

Browse files
committed
示例代码
1 parent ca4cf4a commit 4e7cf2f

13 files changed

Lines changed: 442 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.example.lvruheng.autoflowlayout;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.widget.Button;
9+
import android.widget.TextView;
10+
11+
import com.example.library.AutoFlowLayout;
12+
13+
/**
14+
* Created by lvruheng on 2017/8/4.
15+
*/
16+
17+
public class NormalFlowActivity extends AppCompatActivity implements View.OnClickListener {
18+
private AutoFlowLayout mFlowLayout;
19+
private String[] mData = {"Java","C++","Python","JavaScript","Ruby","Swift","MATLAB","Scratch","Drat","ABAP","COBOL","Fortran","Scala","Lisp",
20+
"Kotlin","Erlang","Groovy","Scheme","Rust","Logo","Prolog","LabVIEW"};
21+
private LayoutInflater mLayoutInflater;
22+
private Button mSingleButton;
23+
private Button mMultiLineButton;
24+
private Button mAddButton;
25+
private Button mDeleteButton;
26+
private Button mMultiSelectedButton;
27+
private Button mCenterButton;
28+
private int count = 10;
29+
@Override
30+
protected void onCreate(@Nullable Bundle savedInstanceState) {
31+
super.onCreate(savedInstanceState);
32+
setContentView(R.layout.normal_flow);
33+
mFlowLayout = (AutoFlowLayout) findViewById(R.id.afl_cotent);
34+
mLayoutInflater = LayoutInflater.from(this);
35+
mSingleButton = (Button) findViewById(R.id.bt_single);
36+
mMultiLineButton = (Button) findViewById(R.id.bt_multi);
37+
mAddButton = (Button) findViewById(R.id.bt_add);
38+
mDeleteButton = (Button) findViewById(R.id.bt_delete);
39+
mMultiSelectedButton = (Button) findViewById(R.id.bt_checked);
40+
mCenterButton = (Button) findViewById(R.id.bt_center);
41+
mSingleButton.setOnClickListener(this);
42+
mMultiLineButton.setOnClickListener(this);
43+
mAddButton.setOnClickListener(this);
44+
mDeleteButton.setOnClickListener(this);
45+
mMultiSelectedButton.setOnClickListener(this);
46+
mCenterButton.setOnClickListener(this);
47+
for (int i = 0; i< 10; i ++ ){
48+
View item = mLayoutInflater.inflate(R.layout.sub_item, null);
49+
TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag);
50+
tvAttrTag.setText(mData[i]);
51+
mFlowLayout.addView(item);
52+
}
53+
}
54+
55+
@Override
56+
public void onClick(View view) {
57+
switch (view.getId()) {
58+
case R.id.bt_single:{
59+
mFlowLayout.setLineCenter(false);
60+
mFlowLayout.setSingleLine(true);
61+
mFlowLayout.setMaxLines(1);
62+
break;
63+
}
64+
case R.id.bt_multi:{
65+
mFlowLayout.setLineCenter(false);
66+
mFlowLayout.setSingleLine(false);
67+
mFlowLayout.setMaxLines(2);
68+
break;
69+
}
70+
case R.id.bt_add:{
71+
mFlowLayout.setLineCenter(false);
72+
if (count>=mData.length){
73+
return;
74+
}
75+
View item = mLayoutInflater.inflate(R.layout.sub_item, null);
76+
TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag);
77+
tvAttrTag.setText(mData[count]);
78+
mFlowLayout.setSingleLine(false);
79+
mFlowLayout.setMaxLines(Integer.MAX_VALUE);
80+
mFlowLayout.addView(item);
81+
count++;
82+
break;
83+
}
84+
case R.id.bt_delete:{
85+
mFlowLayout.setLineCenter(false);
86+
mFlowLayout.deleteView();
87+
break;
88+
}
89+
90+
case R.id.bt_checked:{
91+
mFlowLayout.setLineCenter(false);
92+
mFlowLayout.setMultiChecked(true);
93+
break;
94+
}
95+
case R.id.bt_center:{
96+
mFlowLayout.setLineCenter(true);
97+
break;
98+
}
99+
100+
101+
102+
103+
}
104+
}
105+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.example.lvruheng.autoflowlayout;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.widget.Button;
9+
10+
import com.example.library.AutoFlowLayout;
11+
import com.example.library.FlowAdapter;
12+
13+
import java.util.Arrays;
14+
15+
/**
16+
* Created by lvruheng on 2017/8/4.
17+
*/
18+
19+
public class NormalGridActivity extends AppCompatActivity implements View.OnClickListener{
20+
private Button mAddButton;
21+
private Button mDeleteButton;
22+
private AutoFlowLayout mFlowLayout;
23+
private int count =6;
24+
private String[] mData = {"Java", "C++", "Python", "JavaScript", "Ruby", "Swift"};
25+
private LayoutInflater mLayoutInflater;
26+
@Override
27+
protected void onCreate(@Nullable Bundle savedInstanceState) {
28+
super.onCreate(savedInstanceState);
29+
setContentView(R.layout.normal_grid);
30+
mAddButton = (Button) findViewById(R.id.bt_add);
31+
mDeleteButton = (Button) findViewById(R.id.bt_delete);
32+
mAddButton.setOnClickListener(this);
33+
mDeleteButton.setOnClickListener(this);
34+
mLayoutInflater = LayoutInflater.from(this);
35+
mFlowLayout = (AutoFlowLayout) findViewById(R.id.afl_cotent);
36+
mFlowLayout.setAdapter(new FlowAdapter(Arrays.asList(mData)) {
37+
@Override
38+
public View getView(int position) {
39+
View item = mLayoutInflater.inflate(R.layout.grid_item, null);
40+
return item;
41+
}
42+
});
43+
}
44+
45+
@Override
46+
public void onClick(View view) {
47+
switch (view.getId()) {
48+
case R.id.bt_add:{
49+
count++;
50+
mFlowLayout.setRowNumbers(count%3 == 0 ? count/3 : count/3 + 1);
51+
View item = mLayoutInflater.inflate(R.layout.grid_item, null);
52+
mFlowLayout.addView(item);
53+
break;
54+
}
55+
case R.id.bt_delete:{
56+
count--;
57+
mFlowLayout.setRowNumbers(count%3 == 0 ? count/3 : count/3 + 1);
58+
mFlowLayout.deleteView();
59+
break;
60+
}
61+
}
62+
}
63+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.example.lvruheng.autoflowlayout;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.widget.Button;
9+
import android.widget.ImageView;
10+
import android.widget.TextView;
11+
import android.widget.Toast;
12+
13+
import com.example.library.AutoFlowLayout;
14+
import com.example.library.FlowAdapter;
15+
16+
import java.util.Arrays;
17+
18+
/**
19+
* Created by lvruheng on 2017/8/4.
20+
*/
21+
22+
public class SpecialFlowActivity extends AppCompatActivity {
23+
private Button mChangeButton;
24+
private Button mLongClickButton;
25+
private AutoFlowLayout mFlowLayout;
26+
private String[] mData = {"Java", "C++", "Python", "JavaScript", "Ruby", "Swift", "MATLAB", "Scratch", "Drat", "ABAP", "COBOL", "Fortran", "Scala", "Lisp",
27+
"Kotlin", "Erlang", "Groovy", "Scheme", "Rust", "Logo", "Prolog", "LabVIEW"};
28+
private LayoutInflater mLayoutInflater;
29+
30+
@Override
31+
protected void onCreate(@Nullable Bundle savedInstanceState) {
32+
super.onCreate(savedInstanceState);
33+
setContentView(R.layout.special_flow);
34+
mChangeButton = (Button) findViewById(R.id.bt_change);
35+
mLayoutInflater = LayoutInflater.from(this);
36+
mLongClickButton = (Button) findViewById(R.id.bt_long_click);
37+
mFlowLayout = (AutoFlowLayout) findViewById(R.id.afl_cotent);
38+
mFlowLayout.setAdapter(new FlowAdapter(Arrays.asList(mData)) {
39+
@Override
40+
public View getView(int position) {
41+
View item = mLayoutInflater.inflate(R.layout.special_item, null);
42+
TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag);
43+
tvAttrTag.setText(mData[position]);
44+
return item;
45+
}
46+
});
47+
mFlowLayout.setOnItemClickListener(new AutoFlowLayout.OnItemClickListener() {
48+
@Override
49+
public void onItemClick(int position, View view) {
50+
Toast.makeText(SpecialFlowActivity.this, mData[position], Toast.LENGTH_SHORT).show();
51+
}
52+
});
53+
mFlowLayout.setOnLongItemClickListener(new AutoFlowLayout.OnLongItemClickListener() {
54+
@Override
55+
public void onLongItemClick(int position, View view) {
56+
ImageView imageView = view.findViewById(R.id.iv_delete);
57+
imageView.setVisibility(View.VISIBLE);
58+
}
59+
});
60+
}
61+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.example.lvruheng.autoflowlayout;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
9+
import com.example.library.AutoFlowLayout;
10+
import com.example.library.FlowAdapter;
11+
12+
import java.util.Arrays;
13+
14+
/**
15+
* Created by lvruheng on 2017/8/4.
16+
*/
17+
18+
public class SpecialGridActivity extends AppCompatActivity {
19+
private AutoFlowLayout mFlowLayout;
20+
private LayoutInflater mLayoutInflater;
21+
private String[] mData = {"Java", "C++", "Python", "JavaScript", "Ruby", "Swift","Swift","MATLAB","Scratch"};
22+
@Override
23+
protected void onCreate(@Nullable Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
setContentView(R.layout.special_grid);
26+
mLayoutInflater = LayoutInflater.from(this);
27+
mFlowLayout = (AutoFlowLayout) findViewById(R.id.afl_cotent);
28+
mFlowLayout.setAdapter(new FlowAdapter(Arrays.asList(mData)) {
29+
@Override
30+
public View getView(int position) {
31+
View item = mLayoutInflater.inflate(R.layout.special_grid_item, null);
32+
return item;
33+
}
34+
});
35+
}
36+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_enabled="false" android:color="#999999" />
4+
<item android:state_pressed="true" android:color="#7f222222"/>
5+
<item android:color="#222222" />
6+
</selector>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
3+
<item android:state_selected="true">
4+
<shape>
5+
<corners android:radius="2dp" />
6+
<solid android:color="#7f999999" />
7+
<stroke android:width="1px"
8+
android:color="#d8d8d8"></stroke>
9+
</shape>
10+
</item>
11+
<item>
12+
<shape>
13+
<corners android:radius="2dp" />
14+
<solid android:color="#f4f5f6" />
15+
<stroke android:width="1px"
16+
android:color="#d8d8d8"></stroke>
17+
</shape>
18+
</item>
19+
</selector>
209 Bytes
Loading
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
<com.example.library.AutoFlowLayout
6+
android:id="@+id/afl_cotent"
7+
android:layout_width="match_parent"
8+
android:layout_height="wrap_content"/>
9+
<LinearLayout
10+
android:gravity="center"
11+
android:layout_alignParentBottom="true"
12+
android:orientation="horizontal"
13+
android:layout_width="wrap_content"
14+
android:layout_height="wrap_content">
15+
<Button
16+
android:id="@+id/bt_add"
17+
android:text="添加"
18+
android:layout_weight="1"
19+
android:layout_width="0dp"
20+
android:layout_height="match_parent"/>
21+
<Button
22+
android:id="@+id/bt_delete"
23+
android:text="删除"
24+
android:layout_weight="1"
25+
android:layout_width="0dp"
26+
android:layout_height="match_parent"/>
27+
<Button
28+
android:id="@+id/bt_single"
29+
android:text="单行"
30+
android:layout_weight="1"
31+
android:layout_width="0dp"
32+
android:layout_height="match_parent"/>
33+
<Button
34+
android:id="@+id/bt_multi"
35+
android:text="多行"
36+
android:layout_weight="1"
37+
android:layout_width="0dp"
38+
android:layout_height="match_parent"/>
39+
<Button
40+
android:id="@+id/bt_center"
41+
android:text="居中"
42+
android:layout_weight="1"
43+
android:layout_width="0dp"
44+
android:layout_height="match_parent"/>
45+
<Button
46+
android:id="@+id/bt_checked"
47+
android:text="多选"
48+
android:layout_weight="1"
49+
android:layout_width="0dp"
50+
android:layout_height="match_parent"/>
51+
</LinearLayout>
52+
</RelativeLayout>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
xmlns:app="http://schemas.android.com/apk/res-auto">
6+
<com.example.library.AutoFlowLayout
7+
android:id="@+id/afl_cotent"
8+
app:columnNumbers="3"
9+
app:rowNumbers="2"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"/>
12+
<LinearLayout
13+
android:gravity="center"
14+
android:layout_alignParentBottom="true"
15+
android:orientation="horizontal"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content">
18+
<Button
19+
android:id="@+id/bt_add"
20+
android:text="添加"
21+
android:layout_weight="1"
22+
android:layout_width="0dp"
23+
android:layout_height="match_parent"/>
24+
<Button
25+
android:id="@+id/bt_delete"
26+
android:text="删除"
27+
android:layout_weight="1"
28+
android:layout_width="0dp"
29+
android:layout_height="match_parent"/>
30+
</LinearLayout>
31+
</RelativeLayout>

0 commit comments

Comments
 (0)