├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── scut │ │ └── carson_ho │ │ └── v_layoutusage │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── scut │ │ │ └── carson_ho │ │ │ └── v_layoutusage │ │ │ ├── DividerItemDecoration.java │ │ │ ├── MainActivity.java │ │ │ ├── MyAdapter.java │ │ │ └── MyItemClickListener.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── item.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── scut │ └── carson_ho │ └── v_layoutusage │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | V-Layout Usage -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | Android 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 62 | 63 | 64 | 65 | 66 | 1.8 67 | 68 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "24.0.2" 6 | 7 | defaultConfig { 8 | applicationId "scut.carson_ho.v_layoutusage" 9 | minSdkVersion 19 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.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 ('com.alibaba.android:vlayout:1.0.3@aar') { 24 | transitive = true 25 | } 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | testCompile 'junit:junit:4.12' 28 | compile 'com.android.support:appcompat-v7:23.4.0' 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Carson_Ho/Library/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 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/scut/carson_ho/v_layoutusage/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package scut.carson_ho.v_layoutusage; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/scut/carson_ho/v_layoutusage/DividerItemDecoration.java: -------------------------------------------------------------------------------- 1 | package scut.carson_ho.v_layoutusage; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.Rect; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.util.TypedValue; 11 | import android.view.View; 12 | 13 | /** 14 | * Created by Carson_Ho on 17/4/29. 15 | */ 16 | public class DividerItemDecoration extends RecyclerView.ItemDecoration { 17 | /* 18 | * RecyclerView的布局方向,默认先赋值 19 | * 为纵向布局 20 | * RecyclerView 布局可横向,也可纵向 21 | * 横向和纵向对应的分割想画法不一样 22 | * */ 23 | private int mOrientation = LinearLayoutManager.VERTICAL ; 24 | 25 | /** 26 | * item之间分割线的size,默认为1 27 | */ 28 | private int mItemSize = 1 ; 29 | 30 | /** 31 | * 绘制item分割线的画笔,和设置其属性 32 | * 来绘制个性分割线 33 | */ 34 | private Paint mPaint ; 35 | 36 | /** 37 | * 构造方法传入布局方向,不可不传 38 | * @param context 39 | * @param orientation 40 | */ 41 | public DividerItemDecoration(Context context,int orientation) { 42 | this.mOrientation = orientation; 43 | if(orientation != LinearLayoutManager.VERTICAL && orientation != LinearLayoutManager.HORIZONTAL){ 44 | throw new IllegalArgumentException("请传入正确的参数") ; 45 | } 46 | mItemSize = (int) TypedValue.applyDimension(mItemSize, TypedValue.COMPLEX_UNIT_DIP, context.getResources().getDisplayMetrics()); 47 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG) ; 48 | mPaint.setColor(Color.BLUE); 49 | /*设置填充*/ 50 | mPaint.setStyle(Paint.Style.FILL); 51 | } 52 | 53 | @Override 54 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 55 | if(mOrientation == LinearLayoutManager.VERTICAL){ 56 | drawVertical(c,parent) ; 57 | }else { 58 | drawHorizontal(c,parent) ; 59 | } 60 | } 61 | 62 | /** 63 | * 绘制纵向 item 分割线 64 | * @param canvas 65 | * @param parent 66 | */ 67 | private void drawVertical(Canvas canvas,RecyclerView parent){ 68 | final int left = parent.getPaddingLeft() ; 69 | final int right = parent.getMeasuredWidth() - parent.getPaddingRight() ; 70 | final int childSize = parent.getChildCount() ; 71 | for(int i = 0 ; i < childSize ; i ++){ 72 | final View child = parent.getChildAt( i ) ; 73 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); 74 | final int top = child.getBottom() + layoutParams.bottomMargin ; 75 | final int bottom = top + mItemSize ; 76 | canvas.drawRect(left,top,right,bottom,mPaint); 77 | } 78 | } 79 | 80 | /** 81 | * 绘制横向 item 分割线 82 | * @param canvas 83 | * @param parent 84 | */ 85 | private void drawHorizontal(Canvas canvas,RecyclerView parent){ 86 | final int top = parent.getPaddingTop() ; 87 | final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom() ; 88 | final int childSize = parent.getChildCount() ; 89 | for(int i = 0 ; i < childSize ; i ++){ 90 | final View child = parent.getChildAt( i ) ; 91 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); 92 | final int left = child.getRight() + layoutParams.rightMargin ; 93 | final int right = left + mItemSize ; 94 | canvas.drawRect(left,top,right,bottom,mPaint); 95 | } 96 | } 97 | 98 | /** 99 | * 设置item分割线的size 100 | * @param outRect 101 | * @param view 102 | * @param parent 103 | * @param state 104 | */ 105 | @Override 106 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 107 | if(mOrientation == LinearLayoutManager.VERTICAL){ 108 | outRect.set(0,0,0,mItemSize); 109 | }else { 110 | outRect.set(0,0,mItemSize,0); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /app/src/main/java/scut/carson_ho/v_layoutusage/MainActivity.java: -------------------------------------------------------------------------------- 1 | package scut.carson_ho.v_layoutusage; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.Toast; 10 | 11 | import com.alibaba.android.vlayout.DelegateAdapter; 12 | import com.alibaba.android.vlayout.VirtualLayoutManager; 13 | import com.alibaba.android.vlayout.layout.ColumnLayoutHelper; 14 | import com.alibaba.android.vlayout.layout.FixLayoutHelper; 15 | import com.alibaba.android.vlayout.layout.FloatLayoutHelper; 16 | import com.alibaba.android.vlayout.layout.GridLayoutHelper; 17 | import com.alibaba.android.vlayout.layout.LinearLayoutHelper; 18 | import com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper; 19 | import com.alibaba.android.vlayout.layout.ScrollFixLayoutHelper; 20 | import com.alibaba.android.vlayout.layout.SingleLayoutHelper; 21 | import com.alibaba.android.vlayout.layout.StaggeredGridLayoutHelper; 22 | import com.alibaba.android.vlayout.layout.StickyLayoutHelper; 23 | 24 | import java.util.ArrayList; 25 | import java.util.HashMap; 26 | import java.util.LinkedList; 27 | import java.util.List; 28 | 29 | public class MainActivity extends AppCompatActivity implements MyItemClickListener { 30 | RecyclerView recyclerView; 31 | MyAdapter Adapter_linearLayout,Adapter_GridLayout,Adapter_FixLayout,Adapter_ScrollFixLayout 32 | ,Adapter_FloatLayout,Adapter_ColumnLayout,Adapter_SingleLayout,Adapter_onePlusNLayout, 33 | Adapter_StickyLayout,Adapter_StaggeredGridLayout; 34 | private ArrayList> listItem; 35 | 36 | @Override 37 | protected void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | setContentView(R.layout.activity_main); 40 | 41 | /** 42 | * 步骤1:创建RecyclerView & VirtualLayoutManager 对象并进行绑定 43 | * */ 44 | recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); 45 | // 创建RecyclerView对象 46 | 47 | VirtualLayoutManager layoutManager = new VirtualLayoutManager(this); 48 | // 创建VirtualLayoutManager对象 49 | // 同时内部会创建一个LayoutHelperFinder对象,用来后续的LayoutHelper查找 50 | 51 | recyclerView.setLayoutManager(layoutManager); 52 | // 将VirtualLayoutManager绑定到recyclerView 53 | 54 | /** 55 | * 步骤2:设置组件复用回收池 56 | * */ 57 | RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool(); 58 | recyclerView.setRecycledViewPool(viewPool); 59 | viewPool.setMaxRecycledViews(0, 10); 60 | 61 | 62 | /** 63 | * 步骤3:设置需要存放的数据 64 | * */ 65 | listItem = new ArrayList>(); 66 | for (int i = 0; i < 100; i++) { 67 | HashMap map = new HashMap(); 68 | map.put("ItemTitle", "第" + i + "行"); 69 | map.put("ItemImage", R.mipmap.ic_launcher); 70 | listItem.add(map); 71 | 72 | } 73 | 74 | 75 | 76 | 77 | 78 | /** 79 | * 步骤4:根据数据列表,创建对应的LayoutHelper 80 | * */ 81 | 82 | // 为了展示效果,此处将上面介绍的所有布局都显示出来 83 | 84 | /** 85 | 设置线性布局 86 | */ 87 | LinearLayoutHelper linearLayoutHelper = new LinearLayoutHelper(); 88 | // 创建对应的LayoutHelper对象 89 | 90 | // 公共属性 91 | linearLayoutHelper.setItemCount(4);// 设置布局里Item个数 92 | linearLayoutHelper.setPadding(20, 20, 20, 20);// 设置LayoutHelper的子元素相对LayoutHelper边缘的距离 93 | linearLayoutHelper.setMargin(20, 20, 20, 20);// 设置LayoutHelper边缘相对父控件(即RecyclerView)的距离 94 | // linearLayoutHelper.setBgColor(Color.GRAY);// 设置背景颜色 95 | linearLayoutHelper.setAspectRatio(6);// 设置设置布局内每行布局的宽与高的比 96 | 97 | // linearLayoutHelper特有属性 98 | linearLayoutHelper.setDividerHeight(10); 99 | // 设置间隔高度 100 | // 设置的间隔会与RecyclerView的addItemDecoration()添加的间隔叠加. 101 | 102 | linearLayoutHelper.setMarginBottom(100); 103 | // 设置布局底部与下个布局的间隔 104 | 105 | 106 | // 创建自定义的Adapter对象 & 绑定数据 & 绑定对应的LayoutHelper进行布局绘制 107 | Adapter_linearLayout = new MyAdapter(this, linearLayoutHelper, 4, listItem) { 108 | // 参数2:绑定绑定对应的LayoutHelper 109 | // 参数3:传入该布局需要显示的数据个数 110 | // 参数4:传入需要绑定的数据 111 | 112 | // 通过重写onBindViewHolder()设置更丰富的布局效果 113 | @Override 114 | public void onBindViewHolder(MainViewHolder holder, int position) { 115 | super.onBindViewHolder(holder, position); 116 | // 为了展示效果,将布局的第一个数据设置为linearLayout 117 | if (position == 0) { 118 | holder.Text.setText("Linear"); 119 | } 120 | 121 | //为了展示效果,将布局里不同位置的Item进行背景颜色设置 122 | if (position < 2) { 123 | holder.itemView.setBackgroundColor(0x66cc0000 + (position - 6) * 128); 124 | } else if (position % 2 == 0) { 125 | holder.itemView.setBackgroundColor(0xaa22ff22); 126 | } else { 127 | holder.itemView.setBackgroundColor(0xccff22ff); 128 | } 129 | 130 | 131 | } 132 | }; 133 | 134 | Adapter_linearLayout.setOnItemClickListener(this); 135 | // 设置每个Item的点击事件 136 | 137 | 138 | /** 139 | 设置吸边布局 140 | */ 141 | StickyLayoutHelper stickyLayoutHelper = new StickyLayoutHelper(); 142 | 143 | // 公共属性 144 | stickyLayoutHelper.setItemCount(3);// 设置布局里Item个数 145 | stickyLayoutHelper.setPadding(20, 20, 20, 20);// 设置LayoutHelper的子元素相对LayoutHelper边缘的距离 146 | stickyLayoutHelper.setMargin(20, 20, 20, 20);// 设置LayoutHelper边缘相对父控件(即RecyclerView)的距离 147 | stickyLayoutHelper.setBgColor(Color.GRAY);// 设置背景颜色 148 | stickyLayoutHelper.setAspectRatio(3);// 设置设置布局内每行布局的宽与高的比 149 | 150 | // 特有属性 151 | stickyLayoutHelper.setStickyStart(true); 152 | // true = 组件吸在顶部 153 | // false = 组件吸在底部 154 | 155 | stickyLayoutHelper.setOffset(100);// 设置吸边位置的偏移量 156 | 157 | Adapter_StickyLayout = new MyAdapter(this, stickyLayoutHelper,1, listItem) { 158 | // 设置需要展示的数据总数,此处设置是1 159 | // 为了展示效果,通过重写onBindViewHolder()将布局的第一个数据设置为Stick 160 | @Override 161 | public void onBindViewHolder(MainViewHolder holder, int position) { 162 | super.onBindViewHolder(holder, position); 163 | if (position == 0) { 164 | holder.Text.setText("Stick"); 165 | } 166 | } 167 | }; 168 | 169 | Adapter_StickyLayout.setOnItemClickListener(this); 170 | // 设置每个Item的点击事件 171 | 172 | 173 | /** 174 | 设置可选固定布局 175 | */ 176 | 177 | ScrollFixLayoutHelper scrollFixLayoutHelper = new ScrollFixLayoutHelper(ScrollFixLayoutHelper.TOP_RIGHT,0,0); 178 | // 参数说明: 179 | // 参数1:设置吸边时的基准位置(alignType) - 有四个取值:TOP_LEFT(默认), TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT 180 | // 参数2:基准位置的偏移量x 181 | // 参数3:基准位置的偏移量y 182 | 183 | 184 | 185 | // 公共属性 186 | scrollFixLayoutHelper.setItemCount(1);// 设置布局里Item个数 187 | // 从设置Item数目的源码可以看出,一个FixLayoutHelper只能设置一个 188 | // @Override 189 | // public void setItemCount(int itemCount) { 190 | // if (itemCount > 0) { 191 | // super.setItemCount(1); 192 | // } else { 193 | // super.setItemCount(0); 194 | // } 195 | // } 196 | scrollFixLayoutHelper.setPadding(20, 20, 20, 20);// 设置LayoutHelper的子元素相对LayoutHelper边缘的距离 197 | scrollFixLayoutHelper.setMargin(20, 20, 20, 20);// 设置LayoutHelper边缘相对父控件(即RecyclerView)的距离 198 | scrollFixLayoutHelper.setBgColor(Color.GRAY);// 设置背景颜色 199 | scrollFixLayoutHelper.setAspectRatio(6);// 设置设置布局内每行布局的宽与高的比 200 | 201 | // fixLayoutHelper特有属性 202 | scrollFixLayoutHelper.setAlignType(FixLayoutHelper.TOP_LEFT);// 设置吸边时的基准位置(alignType) 203 | scrollFixLayoutHelper.setX(30);// 设置基准位置的横向偏移量X 204 | scrollFixLayoutHelper.setY(50);// 设置基准位置的纵向偏移量Y 205 | scrollFixLayoutHelper.setShowType(ScrollFixLayoutHelper.SHOW_ON_LEAVE);// 设置Item的显示模式 206 | 207 | 208 | 209 | Adapter_ScrollFixLayout = new MyAdapter(this, scrollFixLayoutHelper,1, listItem) { 210 | // 设置需要展示的数据总数,此处设置是1 211 | // 为了展示效果,通过重写onBindViewHolder()将布局的第一个数据设置为scrollFix 212 | @Override 213 | public void onBindViewHolder(MainViewHolder holder, int position) { 214 | super.onBindViewHolder(holder, position); 215 | if (position == 0) { 216 | holder.Text.setText("scrollFix"); 217 | } 218 | } 219 | }; 220 | 221 | Adapter_ScrollFixLayout.setOnItemClickListener(this); 222 | // 设置每个Item的点击事件 223 | 224 | 225 | /** 226 | 设置Grid布局 227 | */ 228 | GridLayoutHelper gridLayoutHelper = new GridLayoutHelper(3); 229 | // 在构造函数设置每行的网格个数 230 | 231 | // 公共属性 232 | gridLayoutHelper.setItemCount(36);// 设置布局里Item个数 233 | gridLayoutHelper.setPadding(20, 20, 20, 20);// 设置LayoutHelper的子元素相对LayoutHelper边缘的距离 234 | gridLayoutHelper.setMargin(20, 20, 20, 20);// 设置LayoutHelper边缘相对父控件(即RecyclerView)的距离 235 | // gridLayoutHelper.setBgColor(Color.GRAY);// 设置背景颜色 236 | gridLayoutHelper.setAspectRatio(6);// 设置设置布局内每行布局的宽与高的比 237 | 238 | 239 | // gridLayoutHelper特有属性 240 | gridLayoutHelper.setWeights(new float[]{40, 30, 30});//设置每行中 每个网格宽度 占 每行总宽度 的比例 241 | gridLayoutHelper.setVGap(20);// 控制子元素之间的垂直间距 242 | gridLayoutHelper.setHGap(20);// 控制子元素之间的水平间距 243 | gridLayoutHelper.setAutoExpand(false);//是否自动填充空白区域 244 | gridLayoutHelper.setSpanCount(3);// 设置每行多少个网格 245 | // 通过自定义SpanSizeLookup来控制某个Item的占网格个数 246 | gridLayoutHelper.setSpanSizeLookup(new GridLayoutHelper.SpanSizeLookup() { 247 | @Override 248 | public int getSpanSize(int position) { 249 | if (position > 7) { 250 | return 3; 251 | // 第7个位置后,每个Item占3个网格 252 | } else { 253 | return 2; 254 | // 第7个位置前,每个Item占2个网格 255 | } 256 | } 257 | }); 258 | 259 | Adapter_GridLayout = new MyAdapter(this, gridLayoutHelper,36, listItem) { 260 | // 设置需要展示的数据总数,此处设置是8,即展示总数是8个,然后每行是4个(上面设置的) 261 | // 为了展示效果,通过重写onBindViewHolder()将布局的第一个数据设置为gridLayoutHelper 262 | @Override 263 | public void onBindViewHolder(MainViewHolder holder, int position) { 264 | super.onBindViewHolder(holder, position); 265 | // 为了展示效果,将布局里不同位置的Item进行背景颜色设置 266 | if (position < 2) { 267 | holder.itemView.setBackgroundColor(0x66cc0000 + (position - 6) * 128); 268 | } else if (position % 2 == 0) { 269 | holder.itemView.setBackgroundColor(0xaa22ff22); 270 | } else { 271 | holder.itemView.setBackgroundColor(0xccff22ff); 272 | } 273 | 274 | 275 | 276 | if (position == 0) { 277 | holder.Text.setText("Grid"); 278 | } 279 | } 280 | }; 281 | 282 | Adapter_GridLayout.setOnItemClickListener(this); 283 | // 设置每个Item的点击事件 284 | 285 | /** 286 | 设置固定布局 287 | */ 288 | 289 | FixLayoutHelper fixLayoutHelper = new FixLayoutHelper(FixLayoutHelper.TOP_LEFT,40,100); 290 | // 参数说明: 291 | // 参数1:设置吸边时的基准位置(alignType) - 有四个取值:TOP_LEFT(默认), TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT 292 | // 参数2:基准位置的偏移量x 293 | // 参数3:基准位置的偏移量y 294 | 295 | 296 | // 公共属性 297 | fixLayoutHelper.setItemCount(1);// 设置布局里Item个数 298 | // 从设置Item数目的源码可以看出,一个FixLayoutHelper只能设置一个 299 | // @Override 300 | // public void setItemCount(int itemCount) { 301 | // if (itemCount > 0) { 302 | // super.setItemCount(1); 303 | // } else { 304 | // super.setItemCount(0); 305 | // } 306 | // } 307 | fixLayoutHelper.setPadding(20, 20, 20, 20);// 设置LayoutHelper的子元素相对LayoutHelper边缘的距离 308 | fixLayoutHelper.setMargin(20, 20, 20, 20);// 设置LayoutHelper边缘相对父控件(即RecyclerView)的距离 309 | fixLayoutHelper.setBgColor(Color.GRAY);// 设置背景颜色 310 | fixLayoutHelper.setAspectRatio(6);// 设置设置布局内每行布局的宽与高的比 311 | 312 | // fixLayoutHelper特有属性 313 | fixLayoutHelper.setAlignType(FixLayoutHelper.TOP_LEFT);// 设置吸边时的基准位置(alignType) 314 | fixLayoutHelper.setX(30);// 设置基准位置的横向偏移量X 315 | fixLayoutHelper.setY(50);// 设置基准位置的纵向偏移量Y 316 | 317 | Adapter_FixLayout = new MyAdapter(this, fixLayoutHelper,1, listItem) { 318 | // 设置需要展示的数据总数,此处设置是1 319 | // 为了展示效果,通过重写onBindViewHolder()将布局的第一个数据设置为Fix 320 | @Override 321 | public void onBindViewHolder(MainViewHolder holder, int position) { 322 | super.onBindViewHolder(holder, position); 323 | if (position == 0) { 324 | holder.Text.setText("Fix"); 325 | } 326 | } 327 | }; 328 | 329 | Adapter_FixLayout.setOnItemClickListener(this); 330 | // 设置每个Item的点击事件 331 | 332 | /** 333 | 设置浮动布局 334 | */ 335 | FloatLayoutHelper floatLayoutHelper = new FloatLayoutHelper(); 336 | // 创建FloatLayoutHelper对象 337 | 338 | // 公共属性 339 | floatLayoutHelper.setItemCount(1);// 设置布局里Item个数 340 | // 从设置Item数目的源码可以看出,一个FixLayoutHelper只能设置一个 341 | // @Override 342 | // public void setItemCount(int itemCount) { 343 | // if (itemCount > 0) { 344 | // super.setItemCount(1); 345 | // } else { 346 | // super.setItemCount(0); 347 | // } 348 | // } 349 | floatLayoutHelper.setPadding(20, 20, 20, 20);// 设置LayoutHelper的子元素相对LayoutHelper边缘的距离 350 | floatLayoutHelper.setMargin(20, 20, 20, 20);// 设置LayoutHelper边缘相对父控件(即RecyclerView)的距离 351 | floatLayoutHelper.setBgColor(Color.GRAY);// 设置背景颜色 352 | floatLayoutHelper.setAspectRatio(6);// 设置设置布局内每行布局的宽与高的比 353 | 354 | // floatLayoutHelper特有属性 355 | floatLayoutHelper.setDefaultLocation(300, 300);// 设置布局里Item的初始位置 356 | 357 | Adapter_FloatLayout = new MyAdapter(this, floatLayoutHelper,1, listItem) { 358 | // 设置需要展示的数据总数,此处设置是1 359 | // 为了展示效果,通过重写onBindViewHolder()将布局的第一个数据设置为float 360 | @Override 361 | public void onBindViewHolder(MainViewHolder holder, int position) { 362 | super.onBindViewHolder(holder, position); 363 | ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(500,1000); 364 | holder.itemView.setLayoutParams(layoutParams); 365 | holder.itemView.setBackgroundColor(Color.RED); 366 | 367 | if (position == 0) { 368 | holder.Text.setText("float"); 369 | } 370 | } 371 | }; 372 | 373 | Adapter_FloatLayout.setOnItemClickListener(this); 374 | // 设置每个Item的点击事件 375 | 376 | /** 377 | 设置栏格布局 378 | */ 379 | ColumnLayoutHelper columnLayoutHelper = new ColumnLayoutHelper(); 380 | // 创建对象 381 | 382 | // 公共属性 383 | columnLayoutHelper.setItemCount(3);// 设置布局里Item个数 384 | columnLayoutHelper.setPadding(20, 20, 20, 20);// 设置LayoutHelper的子元素相对LayoutHelper边缘的距离 385 | columnLayoutHelper.setMargin(20, 20, 20, 20);// 设置LayoutHelper边缘相对父控件(即RecyclerView)的距离 386 | columnLayoutHelper.setBgColor(Color.GRAY);// 设置背景颜色 387 | columnLayoutHelper.setAspectRatio(6);// 设置设置布局内每行布局的宽与高的比 388 | 389 | 390 | // columnLayoutHelper特有属性 391 | columnLayoutHelper.setWeights(new float[]{30, 40, 30});// 设置该行每个Item占该行总宽度的比例 392 | 393 | Adapter_ColumnLayout = new MyAdapter(this, columnLayoutHelper,3, listItem) { 394 | // 设置需要展示的数据总数,此处设置是3 395 | // 为了展示效果,通过重写onBindViewHolder()将布局的第一个数据设置为Column 396 | @Override 397 | public void onBindViewHolder(MainViewHolder holder, int position) { 398 | super.onBindViewHolder(holder, position); 399 | if (position == 0) { 400 | holder.Text.setText("Column"); 401 | } 402 | } 403 | }; 404 | 405 | Adapter_ColumnLayout.setOnItemClickListener(this); 406 | // 设置每个Item的点击事件 407 | 408 | /** 409 | 设置通栏布局 410 | */ 411 | 412 | SingleLayoutHelper singleLayoutHelper = new SingleLayoutHelper(); 413 | 414 | // 公共属性 415 | singleLayoutHelper.setItemCount(3);// 设置布局里Item个数 416 | singleLayoutHelper.setPadding(20, 20, 20, 20);// 设置LayoutHelper的子元素相对LayoutHelper边缘的距离 417 | singleLayoutHelper.setMargin(20, 20, 20, 20);// 设置LayoutHelper边缘相对父控件(即RecyclerView)的距离 418 | singleLayoutHelper.setBgColor(Color.GRAY);// 设置背景颜色 419 | singleLayoutHelper.setAspectRatio(6);// 设置设置布局内每行布局的宽与高的比 420 | 421 | 422 | Adapter_SingleLayout = new MyAdapter(this, singleLayoutHelper,1, listItem) { 423 | // 设置需要展示的数据总数,此处设置是1 424 | // 为了展示效果,通过重写onBindViewHolder()将布局的第一个数据设置为Single 425 | @Override 426 | public void onBindViewHolder(MainViewHolder holder, int position) { 427 | super.onBindViewHolder(holder, position); 428 | if (position == 0) { 429 | holder.Text.setText("Single"); 430 | } 431 | } 432 | }; 433 | 434 | Adapter_SingleLayout.setOnItemClickListener(this); 435 | // 设置每个Item的点击事件 436 | 437 | /** 438 | 设置1拖N布局 439 | */ 440 | OnePlusNLayoutHelper onePlusNLayoutHelper = new OnePlusNLayoutHelper(5); 441 | // 在构造函数里传入显示的Item数 442 | // 最多是1拖4,即5个 443 | 444 | // 公共属性 445 | onePlusNLayoutHelper.setItemCount(3);// 设置布局里Item个数 446 | onePlusNLayoutHelper.setPadding(20, 20, 20, 20);// 设置LayoutHelper的子元素相对LayoutHelper边缘的距离 447 | onePlusNLayoutHelper.setMargin(20, 20, 20, 20);// 设置LayoutHelper边缘相对父控件(即RecyclerView)的距离 448 | onePlusNLayoutHelper.setBgColor(Color.GRAY);// 设置背景颜色 449 | onePlusNLayoutHelper.setAspectRatio(3);// 设置设置布局内每行布局的宽与高的比 450 | 451 | 452 | Adapter_onePlusNLayout = new MyAdapter(this, onePlusNLayoutHelper,5, listItem) { 453 | // 设置需要展示的数据总数,此处设置是5,即1拖4 454 | // 为了展示效果,通过重写onBindViewHolder()将布局的第一个数据设置为onePlus 455 | @Override 456 | public void onBindViewHolder(MainViewHolder holder, int position) { 457 | super.onBindViewHolder(holder, position); 458 | if (position == 0) { 459 | holder.Text.setText("onePlus"); 460 | } 461 | } 462 | }; 463 | 464 | Adapter_onePlusNLayout.setOnItemClickListener(this); 465 | // 设置每个Item的点击事件 466 | 467 | /** 468 | 设置瀑布流布局 469 | */ 470 | 471 | StaggeredGridLayoutHelper staggeredGridLayoutHelper = new StaggeredGridLayoutHelper(); 472 | // 创建对象 473 | 474 | // 公有属性 475 | staggeredGridLayoutHelper.setItemCount(20);// 设置布局里Item个数 476 | staggeredGridLayoutHelper.setPadding(20, 20, 20, 20);// 设置LayoutHelper的子元素相对LayoutHelper边缘的距离 477 | staggeredGridLayoutHelper.setMargin(20, 20, 20, 20);// 设置LayoutHelper边缘相对父控件(即RecyclerView)的距离 478 | staggeredGridLayoutHelper.setBgColor(Color.GRAY);// 设置背景颜色 479 | staggeredGridLayoutHelper.setAspectRatio(3);// 设置设置布局内每行布局的宽与高的比 480 | 481 | // 特有属性 482 | staggeredGridLayoutHelper.setLane(3);// 设置控制瀑布流每行的Item数 483 | staggeredGridLayoutHelper.setHGap(20);// 设置子元素之间的水平间距 484 | staggeredGridLayoutHelper.setVGap(15);// 设置子元素之间的垂直间距 485 | 486 | Adapter_StaggeredGridLayout = new MyAdapter(this, staggeredGridLayoutHelper,20, listItem) { 487 | // 设置需要展示的数据总数,此处设置是20 488 | 489 | // 通过重写onBindViewHolder()设置更加丰富的布局 490 | @Override 491 | public void onBindViewHolder(MainViewHolder holder, int position) { 492 | super.onBindViewHolder(holder, position); 493 | ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,150 +position % 5 * 20); 494 | holder.itemView.setLayoutParams(layoutParams); 495 | 496 | // 为了展示效果,设置不同位置的背景色 497 | if (position > 10) { 498 | holder.itemView.setBackgroundColor(0x66cc0000 + (position - 6) * 128); 499 | } else if (position % 2 == 0) { 500 | holder.itemView.setBackgroundColor(0xaa22ff22); 501 | } else { 502 | holder.itemView.setBackgroundColor(0xccff22ff); 503 | } 504 | 505 | // 为了展示效果,通过将布局的第一个数据设置为staggeredGrid 506 | if (position == 0) { 507 | holder.Text.setText("staggeredGrid"); 508 | 509 | 510 | } 511 | } 512 | }; 513 | 514 | Adapter_StaggeredGridLayout.setOnItemClickListener(this); 515 | // 设置每个Item的点击事件 516 | 517 | 518 | /** 519 | *步骤5:将生成的LayoutHelper 交给Adapter,并绑定到RecyclerView 对象 520 | **/ 521 | 522 | // 1. 设置Adapter列表(同时也是设置LayoutHelper列表) 523 | List adapters = new LinkedList<>(); 524 | 525 | // 2. 将上述创建的Adapter对象放入到DelegateAdapter.Adapter列表里 526 | adapters.add(Adapter_linearLayout) ; 527 | adapters.add(Adapter_StickyLayout) ; 528 | adapters.add(Adapter_ScrollFixLayout) ; 529 | adapters.add(Adapter_GridLayout) ; 530 | adapters.add(Adapter_FixLayout) ; 531 | adapters.add(Adapter_FloatLayout) ; 532 | adapters.add(Adapter_ColumnLayout) ; 533 | adapters.add(Adapter_SingleLayout) ; 534 | adapters.add(Adapter_onePlusNLayout) ; 535 | adapters.add(Adapter_StaggeredGridLayout) ; 536 | 537 | 538 | // 539 | // 3. 创建DelegateAdapter对象 & 将layoutManager绑定到DelegateAdapter 540 | DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager); 541 | 542 | // 4. 将DelegateAdapter.Adapter列表绑定到DelegateAdapter 543 | delegateAdapter.setAdapters(adapters); 544 | 545 | // 5. 将delegateAdapter绑定到recyclerView 546 | recyclerView.setAdapter(delegateAdapter); 547 | 548 | 549 | // /** 550 | // *步骤6:设置分割线 & Item之间的间隔 551 | // **/ 552 | // recyclerView.addItemDecoration(new DividerItemDecoration(this, layoutManager.getOrientation())); 553 | // // 需要自定义类DividerItemDecoration 554 | // recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() { 555 | // public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 556 | // outRect.set(5, 5, 5, 5); 557 | // } 558 | // }); 559 | 560 | 561 | } 562 | 563 | /** 564 | *步骤7:实现Item点击事件 565 | **/ 566 | // 点击事件的回调函数 567 | @Override 568 | public void onItemClick(View view, int postion) { 569 | System.out.println("点击了第"+postion+"行"); 570 | Toast.makeText(this, (String) listItem.get(postion).get("ItemTitle"), Toast.LENGTH_SHORT).show(); 571 | } 572 | 573 | } 574 | -------------------------------------------------------------------------------- /app/src/main/java/scut/carson_ho/v_layoutusage/MyAdapter.java: -------------------------------------------------------------------------------- 1 | package scut.carson_ho.v_layoutusage; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.alibaba.android.vlayout.DelegateAdapter; 13 | import com.alibaba.android.vlayout.LayoutHelper; 14 | 15 | import java.util.ArrayList; 16 | import java.util.HashMap; 17 | 18 | /** 19 | * Created by Carson_Ho on 17/4/26. 20 | */ 21 | public class MyAdapter extends DelegateAdapter.Adapter { 22 | // 使用DelegateAdapter首先就是要自定义一个它的内部类Adapter,让LayoutHelper和需要绑定的数据传进去 23 | // 此处的Adapter和普通RecyclerView定义的Adapter只相差了一个onCreateLayoutHelper()方法,其他的都是一样的做法. 24 | 25 | private ArrayList> listItem; 26 | // 用于存放数据列表 27 | 28 | private Context context; 29 | private LayoutHelper layoutHelper; 30 | private RecyclerView.LayoutParams layoutParams; 31 | private int count = 0; 32 | 33 | private MyItemClickListener myItemClickListener; 34 | // 用于设置Item点击事件 35 | 36 | //构造函数(传入每个的数据列表 & 展示的Item数量) 37 | public MyAdapter(Context context, LayoutHelper layoutHelper, int count, ArrayList> listItem) { 38 | this(context, layoutHelper, count, new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300), listItem); 39 | } 40 | 41 | public MyAdapter(Context context, LayoutHelper layoutHelper, int count, @NonNull RecyclerView.LayoutParams layoutParams, ArrayList> listItem) { 42 | this.context = context; 43 | this.layoutHelper = layoutHelper; 44 | this.count = count; 45 | this.layoutParams = layoutParams; 46 | this.listItem = listItem; 47 | 48 | 49 | } 50 | 51 | // 把ViewHolder绑定Item的布局 52 | @Override 53 | public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 54 | return new MainViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false)); 55 | } 56 | 57 | 58 | // 此处的Adapter和普通RecyclerView定义的Adapter只相差了一个onCreateLayoutHelper()方法 59 | @Override 60 | public LayoutHelper onCreateLayoutHelper() { 61 | return layoutHelper; 62 | } 63 | 64 | 65 | // 绑定Item的数据 66 | @Override 67 | public void onBindViewHolder(MainViewHolder holder, int position) { 68 | holder.Text.setText((String) listItem.get(position).get("ItemTitle")); 69 | holder.image.setImageResource((Integer) listItem.get(position).get("ItemImage")); 70 | 71 | 72 | } 73 | 74 | // 返回Item数目 75 | @Override 76 | public int getItemCount() { 77 | return count; 78 | } 79 | 80 | // 设置Item的点击事件 81 | // 绑定MainActivity传进来的点击监听器 82 | public void setOnItemClickListener(MyItemClickListener listener) { 83 | myItemClickListener = listener; 84 | } 85 | 86 | 87 | //定义Viewholder 88 | class MainViewHolder extends RecyclerView.ViewHolder { 89 | public TextView Text; 90 | public ImageView image; 91 | 92 | public MainViewHolder(View root) { 93 | super(root); 94 | 95 | // 绑定视图 96 | Text = (TextView) root.findViewById(R.id.Item); 97 | image = (ImageView) root.findViewById(R.id.Image); 98 | 99 | root.setOnClickListener(new View.OnClickListener() { 100 | @Override 101 | public void onClick(View v) { 102 | if (myItemClickListener != null) 103 | myItemClickListener.onItemClick(v, getPosition()); 104 | } 105 | 106 | } 107 | //监听到点击就回调MainActivity的onItemClick函数 108 | ); 109 | 110 | } 111 | 112 | public TextView getText() { 113 | return Text; 114 | } 115 | 116 | 117 | } 118 | } -------------------------------------------------------------------------------- /app/src/main/java/scut/carson_ho/v_layoutusage/MyItemClickListener.java: -------------------------------------------------------------------------------- 1 | package scut.carson_ho.v_layoutusage; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by Carson_Ho on 17/4/26. 7 | */ 8 | public interface MyItemClickListener { 9 | public void onItemClick(View view,int postion); 10 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 13 | 14 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Carson-Ho/VLayout-Guide/d62d5a1b92d2842e49b27c87b98fb59ebb5bd4c0/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Carson-Ho/VLayout-Guide/d62d5a1b92d2842e49b27c87b98fb59ebb5bd4c0/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Carson-Ho/VLayout-Guide/d62d5a1b92d2842e49b27c87b98fb59ebb5bd4c0/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Carson-Ho/VLayout-Guide/d62d5a1b92d2842e49b27c87b98fb59ebb5bd4c0/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Carson-Ho/VLayout-Guide/d62d5a1b92d2842e49b27c87b98fb59ebb5bd4c0/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | V-Layout Usage 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/scut/carson_ho/v_layoutusage/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package scut.carson_ho.v_layoutusage; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.5.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Carson-Ho/VLayout-Guide/d62d5a1b92d2842e49b27c87b98fb59ebb5bd4c0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 21 11:34:03 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------