├── .gitignore ├── AutoLayoutDemoForEclipse.zip ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── zhy │ │ └── com │ │ └── autolayout │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── zhy │ │ └── com │ │ └── autolayout │ │ └── MainActivity.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── autolayout ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── zhy │ │ └── com │ │ └── autolayout │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zhy │ │ └── autolayout │ │ ├── AutoFrameLayout.java │ │ ├── AutoLayoutActivity.java │ │ ├── AutoLayoutInfo.java │ │ ├── AutoLinearLayout.java │ │ ├── AutoRelativeLayout.java │ │ ├── attr │ │ ├── Attrs.java │ │ ├── AutoAttr.java │ │ ├── HeightAttr.java │ │ ├── MarginAttr.java │ │ ├── MarginBottomAttr.java │ │ ├── MarginLeftAttr.java │ │ ├── MarginRightAttr.java │ │ ├── MarginTopAttr.java │ │ ├── MaxHeightAttr.java │ │ ├── MaxWidthAttr.java │ │ ├── MinHeightAttr.java │ │ ├── MinWidthAttr.java │ │ ├── PaddingAttr.java │ │ ├── PaddingBottomAttr.java │ │ ├── PaddingLeftAttr.java │ │ ├── PaddingRightAttr.java │ │ ├── PaddingTopAttr.java │ │ ├── TextSizeAttr.java │ │ └── WidthAttr.java │ │ ├── config │ │ ├── AutoLayoutConifg.java │ │ └── UseLandscape.java │ │ ├── utils │ │ ├── AutoLayoutHelper.java │ │ ├── AutoUtils.java │ │ ├── L.java │ │ └── ScreenUtils.java │ │ └── widget │ │ └── MetroLayout.java │ └── res │ └── values │ ├── attrs.xml │ ├── ids.xml │ └── strings.xml ├── autolayout_01.png ├── autolayout_02.png ├── autolayout_03.png ├── autolayout_04.png ├── autolayout_06.png ├── autolayout_07.png ├── autolayout_08.png ├── autolayout_09.png ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── preview ├── preview_01.png ├── preview_02.png └── preview_03.png ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── zhy │ │ └── sample │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zhy │ │ └── sample │ │ ├── CategoryActivity.java │ │ ├── MainActivity.java │ │ ├── UseDeviceSizeApplication.java │ │ ├── fragment │ │ ├── ListFragment.java │ │ ├── PayFragment.java │ │ ├── RegisterFragment.java │ │ └── SimpleFragment.java │ │ └── view │ │ └── AutoCardView.java │ └── res │ ├── drawable-hdpi │ ├── daili_xuanzhong.png │ ├── daili_yuanquan.png │ ├── ic_launcher.png │ ├── login_dengluhao.png │ ├── login_fanhui.png │ ├── login_miam.png │ ├── login_yanzhengma.png │ ├── login_zaicishurumima.png │ ├── wode_weixinzhifu.png │ ├── wode_zhifubaozhifu.png │ └── wode_zijin_dise.png │ ├── drawable-xhdpi │ ├── ic_launcher.png │ ├── login_dengluhao.png │ ├── login_miam.png │ ├── login_yanzhengma.png │ ├── login_zaicishurumima.png │ ├── tuijian_dailishangpaihangbang.png │ ├── tuijian_pinpaituijian.png │ ├── tuijian_rexiaopin.png │ ├── tuijian_touxiang6.png │ └── tuijian_xinpintuijia.png │ ├── drawable-xxhdpi │ ├── ic_launcher.png │ ├── login_dengluhao.png │ ├── login_fanhui.png │ ├── login_miam.png │ ├── login_yanzhengma.png │ └── login_zaicishurumima.png │ ├── drawable │ ├── selector_btn_stroke_orange.xml │ ├── selector_pay_radio.xml │ ├── shape_btn_edge_orange.xml │ ├── shape_btn_edge_orange_pre.xml │ └── shape_edit_stroke.xml │ ├── layout │ ├── activity_category.xml │ ├── activity_main.xml │ ├── app_base_title.xml │ ├── fragment_list.xml │ ├── fragment_pay.xml │ ├── fragment_register.xml │ └── list_item.xml │ ├── menu │ ├── menu_main.xml │ └── menu_test.xml │ ├── mipmap-hdpi │ ├── add.png │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── attrs.xml │ ├── color.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── settings.gradle └── widgetsample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── zhy │ └── autolayout │ └── test │ └── widgets │ └── ApplicationTest.java └── main ├── AndroidManifest.xml ├── java └── com │ └── zhy │ └── autolayout │ └── test │ └── widgets │ └── MainActivity.java └── res ├── layout └── activity_main.xml ├── menu └── menu_main.xml ├── mipmap-hdpi └── ic_launcher.png ├── mipmap-mdpi └── ic_launcher.png ├── mipmap-xhdpi └── ic_launcher.png ├── mipmap-xxhdpi └── ic_launcher.png ├── values-w820dp └── dimens.xml └── values ├── dimens.xml ├── strings.xml └── styles.xml /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /captures 3 | 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Generated files 9 | bin/ 10 | gen/ 11 | 12 | # Gradle files 13 | .gradle/ 14 | /build 15 | /*/build/ 16 | 17 | # Local configuration file (sdk path, etc) 18 | local.properties 19 | 20 | # Proguard folder generated by Eclipse 21 | proguard/ 22 | 23 | # Log Files 24 | *.log 25 | 26 | # Eclipse project files 27 | .classpath 28 | .project 29 | .settings/ 30 | 31 | # Intellij project files 32 | *.iml 33 | *.ipr 34 | *.iws 35 | .idea/ 36 | 37 | # System files 38 | .DS_Store -------------------------------------------------------------------------------- /AutoLayoutDemoForEclipse.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/AutoLayoutDemoForEclipse.zip -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidAutoLayout 2 | Android屏幕适配方案,直接填写设计图上的像素尺寸即可完成适配。 3 | 4 | 非常感谢 : 吃土豆的人 的协作。 5 | 6 | ## 效果图 7 | 8 | 最大幅度解决适配问题,并且最大化方便开发者。 9 | 10 | so,看下用法: 11 | 12 | 13 | 14 | 15 | 16 | 17 | 你没有看错,拿到设计稿,在布局文件里面直接填写对应的px即可,px:这里的px并非是Google不建议使用的px,在内部会进行转化处理。 18 | 19 | ok,拿一些实际项目的页面,看下不同分辨率下的效果: 20 | 21 | 左为:768 * 1280 ; 右为:1080 * 1920 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 上述两个机器的分辨率差距挺大了,但是完美实现了适配,最为重要的是: 32 | 33 | * 再也不用拿着设计稿去想这控件的宽高到底取多少dp 34 | * 再也不用去为多个屏幕去写多个dimens 35 | * 再也不用去计算百分比了(如果使用百分比控件完成适配) 36 | * 再也不用去跟UI MM去解释什么是dp了 37 | 38 | 你所要做的就是抄抄设计稿上面的px,直接写入布局文件。 39 | 40 | 还有很多好处,比如上面的Item里面元素比较多,如果标识的比较全面,一个FrameLayout,里面的View填写各种marginLeft,marginTop就能完美实现,几乎不需要嵌套了。 41 | 42 | ## 引入 43 | 44 | * Android Studio 45 | 46 | 将[autolayout](autolayout)引入 47 | 48 | ```xml 49 | dependencies { 50 | compile project(':autolayout') 51 | } 52 | ``` 53 | 54 | 也可以直接 55 | 56 | ``` 57 | dependencies { 58 | compile 'com.zhy:autolayout:1.3.6' 59 | } 60 | ``` 61 | 62 | * Eclipse 63 | 64 | 下载[AutoLayoutDemoForEclipse.zip](AutoLayoutDemoForEclipse.zip),导入到eclipse中即可。 65 | 66 | ## 用法 67 | 68 | ### 第一步: 69 | 70 | 在你的项目的AndroidManifest中注明你的`设计稿`的尺寸。 71 | 72 | ```xml 73 | 74 | 75 | 76 | 77 | 78 | ``` 79 | 80 | ### 第二步: 81 | 82 | 让你的Activity继承自`AutoLayoutActivity`. 83 | 84 | 85 | 非常简单的两个步骤,你就可以开始愉快的编写布局了,详细可以参考sample。 86 | 87 | 88 | 89 | ## 其他用法 90 | 91 | 如果你不希望继承`AutoLayoutActivity`,可以在编写布局文件时,将 92 | 93 | * LinearLayout -> AutoLinearLayout 94 | * RelativeLayout -> AutoRelativeLayout 95 | * FrameLayout -> AutoFrameLayout 96 | 97 | 这样也可以完成适配。 98 | 99 | ## 目前支持属性 100 | 101 | * layout_width 102 | * layout_height 103 | * layout_margin(left,top,right,bottom) 104 | * pading(left,top,right,bottom) 105 | * textSize 106 | * maxWidth, minWidth, maxHeight, minHeight 107 | 108 | 109 | ## 配置 110 | 111 | 默认使用的高度是设备的可用高度,也就是不包括状态栏和底部的操作栏的,如果你希望拿设备的物理高度进行百分比化: 112 | 113 | 可以在Application的onCreate方法中进行设置: 114 | 115 | ```java 116 | public class UseDeviceSizeApplication extends Application 117 | { 118 | @Override 119 | public void onCreate() 120 | { 121 | super.onCreate(); 122 | AutoLayoutConifg.getInstance().useDeviceSize(); 123 | } 124 | } 125 | 126 | ``` 127 | 128 | ## 预览 129 | 130 | 大家都知道,写布局文件的时候,不能实时的去预览效果,那么体验真的是非常的不好,也在很大程度上降低开发效率,所以下面教大家如何用好,用对PreView(针对该库)。 131 | 132 | 首先,你要记得你设计稿的尺寸,比如 `768 * 1280` 133 | 134 | 然后在你的PreView面板,选择于设计图分辨率一致的设备: 135 | 136 | 137 | 138 | 139 | 然后你就可以看到`最为精确的`预览了: 140 | 141 | 142 | 143 | 两个注意事项: 144 | 145 | 1. 你们UI给的设计图的尺寸并非是主流的设计图,该尺寸没找到,你可以自己去新建一个设备。 146 | 2. 不要在PreView中去查看所有分辨率下的显示,是看不出来适配效果的,因为有些计算是动态的。 147 | 148 | ## 扩展 149 | 150 | 对于其他继承系统的FrameLayout、LinearLayout、RelativeLayout的控件,比如`CardView`,如果希望再其内部直接支持"px"百分比化,可以自己扩展,扩展方式为下面的代码,也可参考[issue#21](https://github.com/hongyangAndroid/AndroidAutoLayout/issues/21): 151 | 152 | ``` 153 | package com.zhy.sample.view; 154 | 155 | import android.content.Context; 156 | import android.support.v7.widget.CardView; 157 | import android.util.AttributeSet; 158 | 159 | import com.zhy.autolayout.AutoFrameLayout; 160 | import com.zhy.autolayout.utils.AutoLayoutHelper; 161 | 162 | /** 163 | * Created by zhy on 15/12/8. 164 | */ 165 | public class AutoCardView extends CardView 166 | { 167 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 168 | 169 | public AutoCardView(Context context) 170 | { 171 | super(context); 172 | } 173 | 174 | public AutoCardView(Context context, AttributeSet attrs) 175 | { 176 | super(context, attrs); 177 | } 178 | 179 | public AutoCardView(Context context, AttributeSet attrs, int defStyleAttr) 180 | { 181 | super(context, attrs, defStyleAttr); 182 | } 183 | 184 | @Override 185 | public AutoFrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) 186 | { 187 | return new AutoFrameLayout.LayoutParams(getContext(), attrs); 188 | } 189 | 190 | @Override 191 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 192 | { 193 | if (!isInEditMode()) 194 | { 195 | mHelper.adjustChildren(); 196 | } 197 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 198 | } 199 | 200 | 201 | } 202 | ``` 203 | 204 | 205 | ## 注意事项 206 | 207 | ### ListView、RecyclerView类的Item的适配 208 | 209 | 对于ListView这类控件的item,默认根局部写“px”进行适配是无效的,因为外层非AutoXXXLayout,而是ListView。但是,不用怕,一行代码就可以支持了: 210 | 211 | ```java 212 | @Override 213 | public View getView(int position, View convertView, ViewGroup parent) 214 | { 215 | ViewHolder holder = null; 216 | if (convertView == null) 217 | { 218 | holder = new ViewHolder(); 219 | convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false); 220 | convertView.setTag(holder); 221 | //对于listview,注意添加这一行,即可在item上使用高度 222 | AutoUtils.autoSize(convertView); 223 | } else 224 | { 225 | holder = (ViewHolder) convertView.getTag(); 226 | } 227 | 228 | return convertView; 229 | } 230 | ``` 231 | 232 | 注意` AutoUtils.autoSize(convertView);`这行代码的位置即可。demo中也有相关实例。 233 | 234 | 235 | ### 指定设置的值参考宽度或者高度 236 | 237 | 由于该库的特点,布局文件中宽高上的1px是不相等的,于是如果需要宽高保持一致的情况,布局中使用属性: 238 | 239 | `app:layout_auto_basewidth="height"`,代表height上编写的像素值参考宽度。 240 | 241 | `app:layout_auto_baseheight="width"`,代表width上编写的像素值参考高度。 242 | 243 | 如果需要指定多个值参考宽度即: 244 | 245 | `app:layout_auto_basewidth="height|padding"` 246 | 247 | 用|隔开,类似gravity的用法,取值为: 248 | 249 | * width,height 250 | * margin,marginLeft,marginTop,marginRight,marginBottom 251 | * padding,paddingLeft,paddingTop,paddingRight,paddingBottom 252 | * textSize. 253 | 254 | ### TextView的高度问题 255 | 256 | 设计稿一般只会标识一个字体的大小,比如你设置textSize="20px",实际上TextView所占据的高度肯定大于20px,字的上下都会有一定的建议,所以一定要灵活去写字体的高度,比如对于text上下的margin可以选择尽可能小一点。或者选择别的约束条件去定位(比如上例,选择了marginBottom) 257 | 258 | ##TODO 259 | 260 | * 增加单个Activity横屏布局的支持(设计图必须是横屏的) 261 | * 完善demo(复杂的,简单的,ListView的各种) 262 | 263 | ## 其他信息 264 | 265 | 作者信息: 266 | 267 | * [hongyangAndroid](https://github.com/hongyangAndroid) 268 | * 吃土豆的人 269 | 270 | 271 | 灵感来自: 272 | 273 | * [android-percent-support-lib-sample](https://github.com/JulienGenoud/android-percent-support-lib-sample) 274 | * [android-percent-support-extend](https://github.com/hongyangAndroid/android-percent-support-extend) 275 | * [Android 屏幕适配方案](http://blog.csdn.net/lmj623565791/article/details/45460089) 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | applicationId "zhy.com.autolayout" 9 | minSdkVersion 10 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 fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:23.1.0' 25 | } 26 | -------------------------------------------------------------------------------- /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/zhy/android/sdk/android-sdk-macosx/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/zhy/com/autolayout/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package zhy.com.autolayout; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase 10 | { 11 | public ApplicationTest() 12 | { 13 | super(Application.class); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/zhy/com/autolayout/MainActivity.java: -------------------------------------------------------------------------------- 1 | package zhy.com.autolayout; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.Menu; 6 | import android.view.MenuItem; 7 | 8 | public class MainActivity extends AppCompatActivity 9 | { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) 13 | { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | } 17 | 18 | @Override 19 | public boolean onCreateOptionsMenu(Menu menu) 20 | { 21 | // Inflate the menu; this adds items to the action bar if it is present. 22 | getMenuInflater().inflate(R.menu.menu_main, menu); 23 | return true; 24 | } 25 | 26 | @Override 27 | public boolean onOptionsItemSelected(MenuItem item) 28 | { 29 | // Handle action bar item clicks here. The action bar will 30 | // automatically handle clicks on the Home/Up button, so long 31 | // as you specify a parent activity in AndroidManifest.xml. 32 | int id = item.getItemId(); 33 | 34 | //noinspection SimplifiableIfStatement 35 | if (id == R.id.action_settings) 36 | { 37 | return true; 38 | } 39 | 40 | return super.onOptionsItemSelected(item); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 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 | AutoLayout 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /autolayout/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /autolayout/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | apply plugin: 'com.jfrog.bintray' 4 | 5 | version = "1.3.6" 6 | 7 | android { 8 | compileSdkVersion 23 9 | buildToolsVersion "23.0.1" 10 | 11 | defaultConfig { 12 | minSdkVersion 7 13 | targetSdkVersion 23 14 | versionCode 1 15 | versionName "1.0" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | def siteUrl = 'https://github.com/hongyangAndroid/AndroidAutoLayout' // #CONFIG# // project homepage 26 | def gitUrl = 'https://github.com/hongyangAndroid/AndroidAutoLayout.git' // #CONFIG# // project git 27 | group = "com.zhy" 28 | 29 | install { 30 | repositories.mavenInstaller { 31 | // This generates POM.xml with proper parameters 32 | pom { 33 | project { 34 | packaging 'aar' 35 | name 'AutoLayout' // #CONFIG# // project title 36 | url siteUrl 37 | // Set your license 38 | licenses { 39 | license { 40 | name 'The Apache Software License, Version 2.0' 41 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 42 | } 43 | } 44 | developers { 45 | developer { 46 | id 'hongyangAndroid' // #CONFIG# // your user id (you can write your nickname) 47 | name 'ZhangHongyang' // #CONFIG# // your user name 48 | email '623565791@qq.com' // #CONFIG# // your email 49 | } 50 | } 51 | scm { 52 | connection gitUrl 53 | developerConnection gitUrl 54 | url siteUrl 55 | } 56 | } 57 | } 58 | } 59 | } 60 | 61 | task sourcesJar(type: Jar) { 62 | from android.sourceSets.main.java.srcDirs 63 | classifier = 'sources' 64 | } 65 | 66 | task javadoc(type: Javadoc) { 67 | source = android.sourceSets.main.java.srcDirs 68 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 69 | } 70 | 71 | task javadocJar(type: Jar, dependsOn: javadoc) { 72 | classifier = 'javadoc' 73 | from javadoc.destinationDir 74 | } 75 | 76 | artifacts { 77 | archives javadocJar 78 | archives sourcesJar 79 | } 80 | Properties properties = new Properties() 81 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 82 | bintray { 83 | user = properties.getProperty("bintray.user") 84 | key = properties.getProperty("bintray.apikey") 85 | configurations = ['archives'] 86 | pkg { 87 | repo = "maven" 88 | name = "autolayout" // #CONFIG# project name in jcenter 89 | websiteUrl = siteUrl 90 | vcsUrl = gitUrl 91 | licenses = ["Apache-2.0"] 92 | publish = true 93 | } 94 | } 95 | 96 | 97 | dependencies { 98 | compile fileTree(dir: 'libs', include: ['*.jar']) 99 | compile 'com.android.support:appcompat-v7:23.0.1' 100 | } 101 | -------------------------------------------------------------------------------- /autolayout/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/zhy/android/sdk/android-sdk-macosx/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 | -------------------------------------------------------------------------------- /autolayout/src/androidTest/java/zhy/com/autolayout/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package zhy.com.autolayout; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase 10 | { 11 | public ApplicationTest() 12 | { 13 | super(Application.class); 14 | } 15 | } -------------------------------------------------------------------------------- /autolayout/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/AutoFrameLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.zhy.autolayout; 18 | 19 | import android.annotation.TargetApi; 20 | import android.content.Context; 21 | import android.os.Build; 22 | import android.util.AttributeSet; 23 | import android.view.ViewGroup; 24 | import android.widget.FrameLayout; 25 | import com.zhy.autolayout.utils.AutoLayoutHelper; 26 | 27 | public class AutoFrameLayout extends FrameLayout 28 | { 29 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 30 | 31 | public AutoFrameLayout(Context context) 32 | { 33 | super(context); 34 | } 35 | 36 | public AutoFrameLayout(Context context, AttributeSet attrs) 37 | { 38 | super(context, attrs); 39 | } 40 | 41 | public AutoFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) 42 | { 43 | super(context, attrs, defStyleAttr); 44 | } 45 | 46 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 47 | public AutoFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 48 | super(context, attrs, defStyleAttr, defStyleRes); 49 | } 50 | 51 | @Override 52 | public LayoutParams generateLayoutParams(AttributeSet attrs) 53 | { 54 | return new LayoutParams(getContext(), attrs); 55 | } 56 | 57 | @Override 58 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 59 | { 60 | if (!isInEditMode()) 61 | { 62 | mHelper.adjustChildren(); 63 | } 64 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 65 | } 66 | 67 | @Override 68 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) 69 | { 70 | super.onLayout(changed, left, top, right, bottom); 71 | } 72 | 73 | public static class LayoutParams extends FrameLayout.LayoutParams 74 | implements AutoLayoutHelper.AutoLayoutParams 75 | { 76 | private AutoLayoutInfo mAutoLayoutInfo; 77 | 78 | public LayoutParams(Context c, AttributeSet attrs) 79 | { 80 | super(c, attrs); 81 | 82 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); 83 | } 84 | 85 | public LayoutParams(int width, int height) 86 | { 87 | super(width, height); 88 | } 89 | 90 | public LayoutParams(int width, int height, int gravity) 91 | { 92 | super(width, height, gravity); 93 | } 94 | 95 | public LayoutParams(ViewGroup.LayoutParams source) 96 | { 97 | super(source); 98 | } 99 | 100 | public LayoutParams(MarginLayoutParams source) 101 | { 102 | super(source); 103 | } 104 | 105 | public LayoutParams(FrameLayout.LayoutParams source) 106 | { 107 | super((MarginLayoutParams) source); 108 | gravity = source.gravity; 109 | } 110 | 111 | public LayoutParams(LayoutParams source) 112 | { 113 | this((FrameLayout.LayoutParams) source); 114 | mAutoLayoutInfo = source.mAutoLayoutInfo; 115 | } 116 | 117 | @Override 118 | public AutoLayoutInfo getAutoLayoutInfo() 119 | { 120 | return mAutoLayoutInfo; 121 | } 122 | 123 | 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/AutoLayoutActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout; 2 | 3 | import android.content.Context; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | 8 | ; 9 | 10 | /** 11 | * Created by zhy on 15/11/19. 12 | */ 13 | public class AutoLayoutActivity extends AppCompatActivity 14 | { 15 | private static final String LAYOUT_LINEARLAYOUT = "LinearLayout"; 16 | private static final String LAYOUT_FRAMELAYOUT = "FrameLayout"; 17 | private static final String LAYOUT_RELATIVELAYOUT = "RelativeLayout"; 18 | 19 | 20 | @Override 21 | public View onCreateView(String name, Context context, AttributeSet attrs) 22 | { 23 | View view = null; 24 | if (name.equals(LAYOUT_FRAMELAYOUT)) 25 | { 26 | view = new AutoFrameLayout(context, attrs); 27 | } 28 | 29 | if (name.equals(LAYOUT_LINEARLAYOUT)) 30 | { 31 | view = new AutoLinearLayout(context, attrs); 32 | } 33 | 34 | if (name.equals(LAYOUT_RELATIVELAYOUT)) 35 | { 36 | view = new AutoRelativeLayout(context, attrs); 37 | } 38 | 39 | if (view != null) return view; 40 | 41 | return super.onCreateView(name, context, attrs); 42 | } 43 | 44 | 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/AutoLayoutInfo.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout; 2 | 3 | import android.view.View; 4 | 5 | import com.zhy.autolayout.attr.AutoAttr; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class AutoLayoutInfo 11 | { 12 | private List autoAttrs = new ArrayList<>(); 13 | public void addAttr(AutoAttr autoAttr) 14 | { 15 | autoAttrs.add(autoAttr); 16 | } 17 | 18 | 19 | public void fillAttrs(View view) 20 | { 21 | for (AutoAttr autoAttr : autoAttrs) 22 | { 23 | autoAttr.apply(view); 24 | } 25 | } 26 | 27 | @Override 28 | public String toString() 29 | { 30 | return "AutoLayoutInfo{" + 31 | "autoAttrs=" + autoAttrs + 32 | '}'; 33 | } 34 | } -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/AutoLinearLayout.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.util.AttributeSet; 7 | import android.view.ViewGroup; 8 | import android.widget.LinearLayout; 9 | 10 | import com.zhy.autolayout.utils.AutoLayoutHelper; 11 | 12 | /** 13 | * Created by zhy on 15/6/30. 14 | */ 15 | public class AutoLinearLayout extends LinearLayout 16 | { 17 | 18 | private AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 19 | 20 | public AutoLinearLayout(Context context) { 21 | super(context); 22 | } 23 | 24 | public AutoLinearLayout(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 29 | public AutoLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { 30 | super(context, attrs, defStyleAttr); 31 | } 32 | 33 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 34 | public AutoLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 35 | super(context, attrs, defStyleAttr, defStyleRes); 36 | } 37 | 38 | @Override 39 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 40 | { 41 | if (!isInEditMode()) 42 | mHelper.adjustChildren(); 43 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 44 | } 45 | 46 | 47 | @Override 48 | protected void onLayout(boolean changed, int l, int t, int r, int b) 49 | { 50 | super.onLayout(changed, l, t, r, b); 51 | } 52 | 53 | 54 | @Override 55 | public LayoutParams generateLayoutParams(AttributeSet attrs) 56 | { 57 | return new AutoLinearLayout.LayoutParams(getContext(), attrs); 58 | } 59 | 60 | 61 | public static class LayoutParams extends LinearLayout.LayoutParams 62 | implements AutoLayoutHelper.AutoLayoutParams 63 | { 64 | private AutoLayoutInfo mAutoLayoutInfo; 65 | 66 | public LayoutParams(Context c, AttributeSet attrs) 67 | { 68 | super(c, attrs); 69 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); 70 | } 71 | 72 | @Override 73 | public AutoLayoutInfo getAutoLayoutInfo() 74 | { 75 | return mAutoLayoutInfo; 76 | } 77 | 78 | 79 | public LayoutParams(int width, int height) 80 | { 81 | super(width, height); 82 | } 83 | 84 | 85 | public LayoutParams(ViewGroup.LayoutParams source) 86 | { 87 | super(source); 88 | } 89 | 90 | public LayoutParams(MarginLayoutParams source) 91 | { 92 | super(source); 93 | } 94 | 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/AutoRelativeLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.zhy.autolayout; 18 | 19 | import android.annotation.TargetApi; 20 | import android.content.Context; 21 | import android.os.Build; 22 | import android.util.AttributeSet; 23 | import android.view.ViewGroup; 24 | import android.widget.RelativeLayout; 25 | 26 | import com.zhy.autolayout.utils.AutoLayoutHelper; 27 | 28 | public class AutoRelativeLayout extends RelativeLayout 29 | { 30 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 31 | 32 | public AutoRelativeLayout(Context context) 33 | { 34 | super(context); 35 | } 36 | 37 | public AutoRelativeLayout(Context context, AttributeSet attrs) 38 | { 39 | super(context, attrs); 40 | } 41 | 42 | public AutoRelativeLayout(Context context, AttributeSet attrs, int defStyle) 43 | { 44 | super(context, attrs, defStyle); 45 | } 46 | 47 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 48 | public AutoRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 49 | super(context, attrs, defStyleAttr, defStyleRes); 50 | } 51 | 52 | @Override 53 | public LayoutParams generateLayoutParams(AttributeSet attrs) 54 | { 55 | return new LayoutParams(getContext(), attrs); 56 | } 57 | 58 | @Override 59 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 60 | { 61 | if (!isInEditMode()) 62 | mHelper.adjustChildren(); 63 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 64 | } 65 | 66 | @Override 67 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) 68 | { 69 | super.onLayout(changed, left, top, right, bottom); 70 | } 71 | 72 | 73 | public static class LayoutParams extends RelativeLayout.LayoutParams 74 | implements AutoLayoutHelper.AutoLayoutParams 75 | { 76 | private AutoLayoutInfo mAutoLayoutInfo; 77 | 78 | public LayoutParams(Context c, AttributeSet attrs) 79 | { 80 | super(c, attrs); 81 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); 82 | } 83 | 84 | public LayoutParams(int width, int height) 85 | { 86 | super(width, height); 87 | } 88 | 89 | public LayoutParams(ViewGroup.LayoutParams source) 90 | { 91 | super(source); 92 | } 93 | 94 | public LayoutParams(MarginLayoutParams source) 95 | { 96 | super(source); 97 | } 98 | 99 | @Override 100 | public AutoLayoutInfo getAutoLayoutInfo() 101 | { 102 | return mAutoLayoutInfo; 103 | } 104 | 105 | 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/Attrs.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | /** 4 | * Created by zhy on 15/12/5. 5 | *

6 | * 与attrs.xml中数值对应 7 | */ 8 | public interface Attrs 9 | { 10 | public static final int WIDTH = 1; 11 | public static final int HEIGHT = WIDTH << 1; 12 | public static final int TEXTSIZE = HEIGHT << 1; 13 | public static final int PADDING = TEXTSIZE << 1; 14 | public static final int MARGIN = PADDING << 1; 15 | public static final int MARGIN_LEFT = MARGIN << 1; 16 | public static final int MARGIN_TOP = MARGIN_LEFT << 1; 17 | public static final int MARGIN_RIGHT = MARGIN_TOP << 1; 18 | public static final int MARGIN_BOTTOM = MARGIN_RIGHT << 1; 19 | public static final int PADDING_LEFT = MARGIN_BOTTOM << 1; 20 | public static final int PADDING_TOP = PADDING_LEFT << 1; 21 | public static final int PADDING_RIGHT = PADDING_TOP << 1; 22 | public static final int PADDING_BOTTOM = PADDING_RIGHT << 1; 23 | public static final int MIN_WIDTH = PADDING_BOTTOM << 1; 24 | public static final int MAX_WIDTH = MIN_WIDTH << 1; 25 | public static final int MIN_HEIGHT = MAX_WIDTH << 1; 26 | public static final int MAX_HEIGHT = MIN_HEIGHT << 1; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/AutoAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | import com.zhy.autolayout.utils.AutoUtils; 6 | import com.zhy.autolayout.utils.L; 7 | 8 | 9 | /** 10 | * Created by zhy on 15/12/4. 11 | */ 12 | public abstract class AutoAttr 13 | { 14 | protected int pxVal; 15 | protected int baseWidth; 16 | protected int baseHeight; 17 | 18 | /* 19 | protected boolean isBaseWidth; 20 | protected boolean isBaseDefault; 21 | 22 | public AutoAttr(int pxVal) 23 | { 24 | this.pxVal = pxVal; 25 | isBaseDefault = true; 26 | } 27 | 28 | public AutoAttr(int pxVal, boolean isBaseWidth) 29 | { 30 | this.pxVal = pxVal; 31 | this.isBaseWidth = isBaseWidth; 32 | } 33 | */ 34 | 35 | public AutoAttr(int pxVal, int baseWidth, int baseHeight) 36 | { 37 | this.pxVal = pxVal; 38 | this.baseWidth = baseWidth; 39 | this.baseHeight = baseHeight; 40 | } 41 | 42 | public void apply(View view) 43 | { 44 | 45 | boolean log = view.getTag() != null && view.getTag().toString().equals("auto"); 46 | 47 | if (log) 48 | { 49 | L.e(" pxVal = " + pxVal + " ," + this.getClass().getSimpleName()); 50 | } 51 | int val; 52 | if (useDefault()) 53 | { 54 | val = defaultBaseWidth() ? getPercentWidthSize() : getPercentHeightSize(); 55 | if (log) 56 | { 57 | L.e(" useDefault val= " + val); 58 | } 59 | } else if (baseWidth()) 60 | { 61 | val = getPercentWidthSize(); 62 | if (log) 63 | { 64 | L.e(" baseWidth val= " + val); 65 | } 66 | } else 67 | { 68 | val = getPercentHeightSize(); 69 | if (log) 70 | { 71 | L.e(" baseHeight val= " + val); 72 | } 73 | } 74 | 75 | val = Math.max(val, 1);//for very thin divider 76 | execute(view, val); 77 | } 78 | 79 | protected int getPercentWidthSize() 80 | { 81 | return AutoUtils.getPercentWidthSizeBigger(pxVal); 82 | } 83 | 84 | protected int getPercentHeightSize() 85 | { 86 | return AutoUtils.getPercentHeightSizeBigger(pxVal); 87 | } 88 | 89 | 90 | protected boolean baseWidth() 91 | { 92 | return contains(baseWidth, attrVal()); 93 | } 94 | 95 | protected boolean useDefault() 96 | { 97 | return !contains(baseHeight, attrVal()) && !contains(baseWidth, attrVal()); 98 | } 99 | 100 | protected boolean contains(int baseVal, int flag) 101 | { 102 | return (baseVal & flag) != 0; 103 | } 104 | 105 | protected abstract int attrVal(); 106 | 107 | protected abstract boolean defaultBaseWidth(); 108 | 109 | protected abstract void execute(View view, int val); 110 | 111 | @Override 112 | public String toString() 113 | { 114 | return "AutoAttr{" + 115 | "pxVal=" + pxVal + 116 | ", baseWidth=" + baseWidth() + 117 | ", defaultBaseWidth=" + defaultBaseWidth() + 118 | '}'; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/HeightAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class HeightAttr extends AutoAttr 10 | { 11 | public HeightAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.HEIGHT; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return false; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | ViewGroup.LayoutParams lp = view.getLayoutParams(); 32 | lp.height = val; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/MarginAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class MarginAttr extends AutoAttr 10 | { 11 | public MarginAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.MARGIN; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return false; 26 | } 27 | 28 | @Override 29 | public void apply(View view) 30 | { 31 | if (!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 32 | { 33 | return; 34 | } 35 | if (useDefault()) 36 | { 37 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 38 | lp.leftMargin = lp.rightMargin = getPercentWidthSize(); 39 | lp.topMargin = lp.bottomMargin = getPercentHeightSize(); 40 | return; 41 | } 42 | super.apply(view); 43 | } 44 | 45 | @Override 46 | protected void execute(View view, int val) 47 | { 48 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 49 | lp.leftMargin = lp.rightMargin = lp.topMargin = lp.bottomMargin = val; 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/MarginBottomAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class MarginBottomAttr extends AutoAttr 10 | { 11 | public MarginBottomAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.MARGIN_BOTTOM; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return false; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | if(!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 32 | { 33 | return ; 34 | } 35 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 36 | lp.bottomMargin = val; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/MarginLeftAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class MarginLeftAttr extends AutoAttr 10 | { 11 | public MarginLeftAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.MARGIN_LEFT; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return true; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | if(!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 32 | { 33 | return ; 34 | } 35 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 36 | lp.leftMargin = val; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/MarginRightAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class MarginRightAttr extends AutoAttr 10 | { 11 | public MarginRightAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.MARGIN_RIGHT; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return true; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | if(!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 32 | { 33 | return ; 34 | } 35 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 36 | lp.rightMargin = val; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/MarginTopAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class MarginTopAttr extends AutoAttr 10 | { 11 | public MarginTopAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.MARGIN_TOP; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return false; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | if(!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 32 | { 33 | return ; 34 | } 35 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 36 | lp.topMargin = val; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/MaxHeightAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * Created by zhy on 15/12/24. 9 | */ 10 | public class MaxHeightAttr extends AutoAttr 11 | { 12 | public MaxHeightAttr(int pxVal, int baseWidth, int baseHeight) 13 | { 14 | super(pxVal, baseWidth, baseHeight); 15 | } 16 | 17 | @Override 18 | protected int attrVal() 19 | { 20 | return Attrs.MAX_HEIGHT; 21 | } 22 | 23 | @Override 24 | protected boolean defaultBaseWidth() 25 | { 26 | return false; 27 | } 28 | 29 | @Override 30 | protected void execute(View view, int val) 31 | { 32 | try 33 | { 34 | Method setMaxWidthMethod = view.getClass().getMethod("setMaxHeight", int.class); 35 | setMaxWidthMethod.invoke(view, val); 36 | } catch (Exception ignore) 37 | { 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/MaxWidthAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * Created by zhy on 15/12/24. 9 | */ 10 | public class MaxWidthAttr extends AutoAttr 11 | { 12 | public MaxWidthAttr(int pxVal, int baseWidth, int baseHeight) 13 | { 14 | super(pxVal, baseWidth, baseHeight); 15 | } 16 | 17 | @Override 18 | protected int attrVal() 19 | { 20 | return Attrs.MAX_WIDTH; 21 | } 22 | 23 | @Override 24 | protected boolean defaultBaseWidth() 25 | { 26 | return true; 27 | } 28 | 29 | @Override 30 | protected void execute(View view, int val) 31 | { 32 | try 33 | { 34 | Method setMaxWidthMethod = view.getClass().getMethod("setMaxWidth", int.class); 35 | setMaxWidthMethod.invoke(view, val); 36 | } catch (Exception ignore) 37 | { 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/MinHeightAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * Created by zhy on 15/12/24. 9 | */ 10 | public class MinHeightAttr extends AutoAttr 11 | { 12 | public MinHeightAttr(int pxVal, int baseWidth, int baseHeight) 13 | { 14 | super(pxVal, baseWidth, baseHeight); 15 | } 16 | 17 | @Override 18 | protected int attrVal() 19 | { 20 | return Attrs.MIN_HEIGHT; 21 | } 22 | 23 | @Override 24 | protected boolean defaultBaseWidth() 25 | { 26 | return false; 27 | } 28 | 29 | @Override 30 | protected void execute(View view, int val) 31 | { 32 | try 33 | { 34 | Method setMaxWidthMethod = view.getClass().getMethod("setMinHeight", int.class); 35 | setMaxWidthMethod.invoke(view, val); 36 | } catch (Exception ignore) 37 | { 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/MinWidthAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * Created by zhy on 15/12/24. 9 | */ 10 | public class MinWidthAttr extends AutoAttr 11 | { 12 | public MinWidthAttr(int pxVal, int baseWidth, int baseHeight) 13 | { 14 | super(pxVal, baseWidth, baseHeight); 15 | } 16 | 17 | @Override 18 | protected int attrVal() 19 | { 20 | return Attrs.MIN_WIDTH; 21 | } 22 | 23 | @Override 24 | protected boolean defaultBaseWidth() 25 | { 26 | return true; 27 | } 28 | 29 | @Override 30 | protected void execute(View view, int val) 31 | { 32 | try 33 | { 34 | Method setMaxWidthMethod = view.getClass().getMethod("setMinWidth", int.class); 35 | setMaxWidthMethod.invoke(view, val); 36 | } catch (Exception ignore) 37 | { 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/PaddingAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/12/5. 7 | */ 8 | public class PaddingAttr extends AutoAttr 9 | { 10 | public PaddingAttr(int pxVal, int baseWidth, int baseHeight) 11 | { 12 | super(pxVal, baseWidth, baseHeight); 13 | } 14 | 15 | @Override 16 | protected int attrVal() 17 | { 18 | return Attrs.PADDING; 19 | } 20 | 21 | @Override 22 | public void apply(View view) 23 | { 24 | int l, t, r, b; 25 | if (useDefault()) 26 | { 27 | l = r = getPercentWidthSize(); 28 | t = b = getPercentHeightSize(); 29 | view.setPadding(l, t, r, b); 30 | return; 31 | } 32 | super.apply(view); 33 | } 34 | 35 | @Override 36 | protected boolean defaultBaseWidth() 37 | { 38 | return false; 39 | } 40 | 41 | @Override 42 | protected void execute(View view, int val) 43 | { 44 | view.setPadding(val, val, val, val); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/PaddingBottomAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/12/5. 7 | */ 8 | public class PaddingBottomAttr extends AutoAttr 9 | { 10 | public PaddingBottomAttr(int pxVal, int baseWidth, int baseHeight) 11 | { 12 | super(pxVal, baseWidth, baseHeight); 13 | } 14 | 15 | @Override 16 | protected int attrVal() 17 | { 18 | return Attrs.PADDING_BOTTOM; 19 | } 20 | 21 | @Override 22 | protected boolean defaultBaseWidth() 23 | { 24 | return false; 25 | } 26 | 27 | @Override 28 | protected void execute(View view, int val) 29 | { 30 | int l = view.getPaddingLeft(); 31 | int t = view.getPaddingTop(); 32 | int r = view.getPaddingRight(); 33 | int b = val; 34 | view.setPadding(l, t, r, b); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/PaddingLeftAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/12/5. 7 | */ 8 | public class PaddingLeftAttr extends AutoAttr 9 | { 10 | public PaddingLeftAttr(int pxVal, int baseWidth, int baseHeight) 11 | { 12 | super(pxVal, baseWidth, baseHeight); 13 | } 14 | 15 | @Override 16 | protected int attrVal() 17 | { 18 | return Attrs.PADDING_LEFT; 19 | } 20 | 21 | @Override 22 | protected boolean defaultBaseWidth() 23 | { 24 | return true; 25 | } 26 | 27 | @Override 28 | protected void execute(View view, int val) 29 | { 30 | int l = val; 31 | int t = view.getPaddingTop(); 32 | int r = view.getPaddingRight(); 33 | int b = view.getPaddingBottom(); 34 | view.setPadding(l, t, r, b); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/PaddingRightAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/12/5. 7 | */ 8 | public class PaddingRightAttr extends AutoAttr 9 | { 10 | public PaddingRightAttr(int pxVal, int baseWidth, int baseHeight) 11 | { 12 | super(pxVal, baseWidth, baseHeight); 13 | } 14 | 15 | @Override 16 | protected int attrVal() 17 | { 18 | return Attrs.PADDING_RIGHT; 19 | } 20 | 21 | @Override 22 | protected boolean defaultBaseWidth() 23 | { 24 | return true; 25 | } 26 | 27 | @Override 28 | protected void execute(View view, int val) 29 | { 30 | int l = view.getPaddingLeft(); 31 | int t = view.getPaddingTop(); 32 | int r = val; 33 | int b = view.getPaddingBottom(); 34 | view.setPadding(l, t, r, b); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/PaddingTopAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/12/5. 7 | */ 8 | public class PaddingTopAttr extends AutoAttr 9 | { 10 | public PaddingTopAttr(int pxVal, int baseWidth, int baseHeight) 11 | { 12 | super(pxVal, baseWidth, baseHeight); 13 | } 14 | 15 | @Override 16 | protected int attrVal() 17 | { 18 | return Attrs.PADDING_TOP; 19 | } 20 | 21 | @Override 22 | protected boolean defaultBaseWidth() 23 | { 24 | return false; 25 | } 26 | 27 | @Override 28 | protected void execute(View view, int val) 29 | { 30 | int l = view.getPaddingLeft(); 31 | int t = val; 32 | int r = view.getPaddingRight(); 33 | int b = view.getPaddingBottom(); 34 | view.setPadding(l, t, r, b); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/TextSizeAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.util.TypedValue; 4 | import android.view.View; 5 | import android.widget.TextView; 6 | 7 | /** 8 | * Created by zhy on 15/12/4. 9 | */ 10 | public class TextSizeAttr extends AutoAttr 11 | { 12 | 13 | public TextSizeAttr(int pxVal, int baseWidth, int baseHeight) 14 | { 15 | super(pxVal, baseWidth, baseHeight); 16 | } 17 | 18 | @Override 19 | protected int attrVal() 20 | { 21 | return Attrs.TEXTSIZE; 22 | } 23 | 24 | @Override 25 | protected boolean defaultBaseWidth() 26 | { 27 | return false; 28 | } 29 | 30 | @Override 31 | protected void execute(View view, int val) 32 | { 33 | if (!(view instanceof TextView)) 34 | return; 35 | ((TextView) view).setIncludeFontPadding(false); 36 | ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, val); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/attr/WidthAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class WidthAttr extends AutoAttr 10 | { 11 | public WidthAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.WIDTH; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return true; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | ViewGroup.LayoutParams lp = view.getLayoutParams(); 32 | lp.width = val; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/config/AutoLayoutConifg.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.config; 2 | 3 | import android.content.Context; 4 | import android.content.pm.ApplicationInfo; 5 | import android.content.pm.PackageManager; 6 | 7 | import com.zhy.autolayout.utils.L; 8 | import com.zhy.autolayout.utils.ScreenUtils; 9 | 10 | /** 11 | * Created by zhy on 15/11/18. 12 | */ 13 | public class AutoLayoutConifg 14 | { 15 | 16 | private static AutoLayoutConifg sIntance = new AutoLayoutConifg(); 17 | 18 | 19 | private static final String KEY_DESIGN_WIDTH = "design_width"; 20 | private static final String KEY_DESIGN_HEIGHT = "design_height"; 21 | 22 | private int mScreenWidth; 23 | private int mScreenHeight; 24 | 25 | private int mDesignWidth; 26 | private int mDesignHeight; 27 | 28 | private boolean useDeviceSize; 29 | 30 | 31 | private AutoLayoutConifg() 32 | { 33 | } 34 | 35 | public void checkParams() 36 | { 37 | if (mDesignHeight <= 0 || mDesignWidth <= 0) 38 | { 39 | throw new RuntimeException( 40 | "you must set " + KEY_DESIGN_WIDTH + " and " + KEY_DESIGN_HEIGHT + " in your manifest file."); 41 | } 42 | } 43 | 44 | public AutoLayoutConifg useDeviceSize() 45 | { 46 | useDeviceSize = true; 47 | return this; 48 | } 49 | 50 | 51 | public static AutoLayoutConifg getInstance() 52 | { 53 | return sIntance; 54 | } 55 | 56 | 57 | public int getScreenWidth() 58 | { 59 | return mScreenWidth; 60 | } 61 | 62 | public int getScreenHeight() 63 | { 64 | return mScreenHeight; 65 | } 66 | 67 | public int getDesignWidth() 68 | { 69 | return mDesignWidth; 70 | } 71 | 72 | public int getDesignHeight() 73 | { 74 | return mDesignHeight; 75 | } 76 | 77 | 78 | public void init(Context context) 79 | { 80 | getMetaData(context); 81 | 82 | int[] screenSize = ScreenUtils.getScreenSize(context, useDeviceSize); 83 | mScreenWidth = screenSize[0]; 84 | mScreenHeight = screenSize[1]; 85 | L.e(" screenWidth =" + mScreenWidth + " ,screenHeight = " + mScreenHeight); 86 | } 87 | 88 | private void getMetaData(Context context) 89 | { 90 | PackageManager packageManager = context.getPackageManager(); 91 | ApplicationInfo applicationInfo; 92 | try 93 | { 94 | applicationInfo = packageManager.getApplicationInfo(context 95 | .getPackageName(), PackageManager.GET_META_DATA); 96 | if (applicationInfo != null && applicationInfo.metaData != null) 97 | { 98 | mDesignWidth = (int) applicationInfo.metaData.get(KEY_DESIGN_WIDTH); 99 | mDesignHeight = (int) applicationInfo.metaData.get(KEY_DESIGN_HEIGHT); 100 | } 101 | } catch (PackageManager.NameNotFoundException e) 102 | { 103 | throw new RuntimeException( 104 | "you must set " + KEY_DESIGN_WIDTH + " and " + KEY_DESIGN_HEIGHT + " in your manifest file.", e); 105 | } 106 | 107 | L.e(" designWidth =" + mDesignWidth + " , designHeight = " + mDesignHeight); 108 | } 109 | 110 | 111 | } 112 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/config/UseLandscape.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.config; 2 | 3 | /** 4 | * Created by zhy on 15/12/5. 5 | * 如果Activity设计稿是横屏,继承该接口即可 6 | */ 7 | public interface UseLandscape 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/utils/AutoLayoutHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.zhy.autolayout.utils; 18 | 19 | import android.content.Context; 20 | import android.content.res.TypedArray; 21 | import android.util.AttributeSet; 22 | import android.util.TypedValue; 23 | import android.view.View; 24 | import android.view.ViewGroup; 25 | 26 | import com.zhy.autolayout.AutoLayoutInfo; 27 | import com.zhy.autolayout.R; 28 | import com.zhy.autolayout.attr.HeightAttr; 29 | import com.zhy.autolayout.attr.MarginAttr; 30 | import com.zhy.autolayout.attr.MarginBottomAttr; 31 | import com.zhy.autolayout.attr.MarginLeftAttr; 32 | import com.zhy.autolayout.attr.MarginRightAttr; 33 | import com.zhy.autolayout.attr.MarginTopAttr; 34 | import com.zhy.autolayout.attr.MaxHeightAttr; 35 | import com.zhy.autolayout.attr.MaxWidthAttr; 36 | import com.zhy.autolayout.attr.MinHeightAttr; 37 | import com.zhy.autolayout.attr.MinWidthAttr; 38 | import com.zhy.autolayout.attr.PaddingAttr; 39 | import com.zhy.autolayout.attr.PaddingBottomAttr; 40 | import com.zhy.autolayout.attr.PaddingLeftAttr; 41 | import com.zhy.autolayout.attr.PaddingRightAttr; 42 | import com.zhy.autolayout.attr.PaddingTopAttr; 43 | import com.zhy.autolayout.attr.TextSizeAttr; 44 | import com.zhy.autolayout.attr.WidthAttr; 45 | import com.zhy.autolayout.config.AutoLayoutConifg; 46 | 47 | public class AutoLayoutHelper 48 | { 49 | private final ViewGroup mHost; 50 | 51 | private static final int[] LL = new int[] 52 | { // 53 | android.R.attr.textSize, 54 | android.R.attr.padding,// 55 | android.R.attr.paddingLeft,// 56 | android.R.attr.paddingTop,// 57 | android.R.attr.paddingRight,// 58 | android.R.attr.paddingBottom,// 59 | android.R.attr.layout_width,// 60 | android.R.attr.layout_height,// 61 | android.R.attr.layout_margin,// 62 | android.R.attr.layout_marginLeft,// 63 | android.R.attr.layout_marginTop,// 64 | android.R.attr.layout_marginRight,// 65 | android.R.attr.layout_marginBottom,// 66 | android.R.attr.maxWidth,// 67 | android.R.attr.maxHeight,// 68 | android.R.attr.minWidth,// 69 | android.R.attr.minHeight,//16843072 70 | 71 | 72 | }; 73 | 74 | private static final int INDEX_TEXT_SIZE = 0; 75 | private static final int INDEX_PADDING = 1; 76 | private static final int INDEX_PADDING_LEFT = 2; 77 | private static final int INDEX_PADDING_TOP = 3; 78 | private static final int INDEX_PADDING_RIGHT = 4; 79 | private static final int INDEX_PADDING_BOTTOM = 5; 80 | private static final int INDEX_WIDTH = 6; 81 | private static final int INDEX_HEIGHT = 7; 82 | private static final int INDEX_MARGIN = 8; 83 | private static final int INDEX_MARGIN_LEFT = 9; 84 | private static final int INDEX_MARGIN_TOP = 10; 85 | private static final int INDEX_MARGIN_RIGHT = 11; 86 | private static final int INDEX_MARGIN_BOTTOM = 12; 87 | private static final int INDEX_MAX_WIDTH = 13; 88 | private static final int INDEX_MAX_HEIGHT = 14; 89 | private static final int INDEX_MIN_WIDTH = 15; 90 | private static final int INDEX_MIN_HEIGHT = 16; 91 | 92 | 93 | /** 94 | * move to other place? 95 | */ 96 | private static AutoLayoutConifg mAutoLayoutConifg; 97 | 98 | public AutoLayoutHelper(ViewGroup host) 99 | { 100 | mHost = host; 101 | 102 | if (mAutoLayoutConifg == null) 103 | { 104 | initAutoLayoutConfig(host); 105 | } 106 | 107 | } 108 | 109 | private void initAutoLayoutConfig(ViewGroup host) 110 | { 111 | mAutoLayoutConifg = AutoLayoutConifg.getInstance(); 112 | mAutoLayoutConifg.init(host.getContext()); 113 | } 114 | 115 | 116 | public void adjustChildren() 117 | { 118 | AutoLayoutConifg.getInstance().checkParams(); 119 | 120 | for (int i = 0, n = mHost.getChildCount(); i < n; i++) 121 | { 122 | View view = mHost.getChildAt(i); 123 | ViewGroup.LayoutParams params = view.getLayoutParams(); 124 | 125 | if (params instanceof AutoLayoutParams) 126 | { 127 | AutoLayoutInfo info = 128 | ((AutoLayoutParams) params).getAutoLayoutInfo(); 129 | if (info != null) 130 | { 131 | info.fillAttrs(view); 132 | } 133 | } 134 | } 135 | 136 | } 137 | 138 | public static AutoLayoutInfo getAutoLayoutInfo(Context context, 139 | AttributeSet attrs) 140 | { 141 | 142 | AutoLayoutInfo info = new AutoLayoutInfo(); 143 | 144 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoLayout_Layout); 145 | int baseWidth = a.getInt(R.styleable.AutoLayout_Layout_layout_auto_basewidth, 0); 146 | int baseHeight = a.getInt(R.styleable.AutoLayout_Layout_layout_auto_baseheight, 0); 147 | a.recycle(); 148 | 149 | TypedArray array = context.obtainStyledAttributes(attrs, LL); 150 | 151 | int n = array.getIndexCount(); 152 | 153 | 154 | for (int i = 0; i < n; i++) 155 | { 156 | int index = array.getIndex(i); 157 | // String val = array.getString(index); 158 | // if (!isPxVal(val)) continue; 159 | 160 | if (!isPxVal(array.peekValue(index))) continue; 161 | 162 | int pxVal = 0; 163 | try 164 | { 165 | pxVal = array.getDimensionPixelOffset(index, 0); 166 | } catch (Exception ignore)//not dimension 167 | { 168 | continue; 169 | } 170 | switch (index) 171 | { 172 | case INDEX_TEXT_SIZE: 173 | info.addAttr(new TextSizeAttr(pxVal, baseWidth, baseHeight)); 174 | break; 175 | case INDEX_PADDING: 176 | info.addAttr(new PaddingAttr(pxVal, baseWidth, baseHeight)); 177 | break; 178 | case INDEX_PADDING_LEFT: 179 | info.addAttr(new PaddingLeftAttr(pxVal, baseWidth, baseHeight)); 180 | break; 181 | case INDEX_PADDING_TOP: 182 | info.addAttr(new PaddingTopAttr(pxVal, baseWidth, baseHeight)); 183 | break; 184 | case INDEX_PADDING_RIGHT: 185 | info.addAttr(new PaddingRightAttr(pxVal, baseWidth, baseHeight)); 186 | break; 187 | case INDEX_PADDING_BOTTOM: 188 | info.addAttr(new PaddingBottomAttr(pxVal, baseWidth, baseHeight)); 189 | break; 190 | case INDEX_WIDTH: 191 | info.addAttr(new WidthAttr(pxVal, baseWidth, baseHeight)); 192 | break; 193 | case INDEX_HEIGHT: 194 | info.addAttr(new HeightAttr(pxVal, baseWidth, baseHeight)); 195 | break; 196 | case INDEX_MARGIN: 197 | info.addAttr(new MarginAttr(pxVal, baseWidth, baseHeight)); 198 | break; 199 | case INDEX_MARGIN_LEFT: 200 | info.addAttr(new MarginLeftAttr(pxVal, baseWidth, baseHeight)); 201 | break; 202 | case INDEX_MARGIN_TOP: 203 | info.addAttr(new MarginTopAttr(pxVal, baseWidth, baseHeight)); 204 | break; 205 | case INDEX_MARGIN_RIGHT: 206 | info.addAttr(new MarginRightAttr(pxVal, baseWidth, baseHeight)); 207 | break; 208 | case INDEX_MARGIN_BOTTOM: 209 | info.addAttr(new MarginBottomAttr(pxVal, baseWidth, baseHeight)); 210 | break; 211 | case INDEX_MAX_WIDTH: 212 | info.addAttr(new MaxWidthAttr(pxVal, baseWidth, baseHeight)); 213 | break; 214 | case INDEX_MAX_HEIGHT: 215 | info.addAttr(new MaxHeightAttr(pxVal, baseWidth, baseHeight)); 216 | break; 217 | case INDEX_MIN_WIDTH: 218 | info.addAttr(new MinWidthAttr(pxVal, baseWidth, baseHeight)); 219 | break; 220 | case INDEX_MIN_HEIGHT: 221 | info.addAttr(new MinHeightAttr(pxVal, baseWidth, baseHeight)); 222 | break; 223 | } 224 | } 225 | array.recycle(); 226 | L.e(" getAutoLayoutInfo " + info.toString()); 227 | return info; 228 | } 229 | 230 | private static boolean isPxVal(TypedValue val) 231 | { 232 | if (val != null && val.type == TypedValue.TYPE_DIMENSION && 233 | getComplexUnit(val.data) == TypedValue.COMPLEX_UNIT_PX) 234 | { 235 | return true; 236 | } 237 | return false; 238 | } 239 | 240 | private static int getComplexUnit(int data) 241 | { 242 | return TypedValue.COMPLEX_UNIT_MASK & (data >> TypedValue.COMPLEX_UNIT_SHIFT); 243 | } 244 | 245 | private static boolean isPxVal(String val) 246 | { 247 | if (val.endsWith("px")) 248 | { 249 | return true; 250 | } 251 | return false; 252 | } 253 | 254 | public interface AutoLayoutParams 255 | { 256 | AutoLayoutInfo getAutoLayoutInfo(); 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/utils/AutoUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.utils; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | import com.zhy.autolayout.R; 7 | import com.zhy.autolayout.config.AutoLayoutConifg; 8 | 9 | /** 10 | * Created by zhy on 15/12/4. 11 | */ 12 | public class AutoUtils 13 | { 14 | 15 | /** 16 | * 会直接将view的LayoutParams上设置的width,height直接进行百分比处理 17 | * 18 | * @param view 19 | */ 20 | public static void auto(View view) 21 | { 22 | autoSize(view); 23 | autoPadding(view); 24 | autoMargin(view); 25 | } 26 | 27 | public static void autoMargin(View view) 28 | { 29 | if (!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 30 | return; 31 | 32 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 33 | if (lp == null) return; 34 | 35 | Object tag = view.getTag(R.id.id_tag_autolayout_margin); 36 | if (tag != null) return; 37 | view.setTag(R.id.id_tag_autolayout_margin, "Just Identify"); 38 | 39 | lp.leftMargin = getPercentWidthSize(lp.leftMargin); 40 | lp.topMargin = getPercentHeightSize(lp.topMargin); 41 | lp.rightMargin = getPercentWidthSize(lp.rightMargin); 42 | lp.bottomMargin = getPercentHeightSize(lp.bottomMargin); 43 | 44 | } 45 | 46 | public static void autoPadding(View view) 47 | { 48 | Object tag = view.getTag(R.id.id_tag_autolayout_padding); 49 | if (tag != null) return; 50 | view.setTag(R.id.id_tag_autolayout_padding, "Just Identify"); 51 | 52 | int l = view.getPaddingLeft(); 53 | int t = view.getPaddingTop(); 54 | int r = view.getPaddingRight(); 55 | int b = view.getPaddingBottom(); 56 | 57 | l = getPercentWidthSize(l); 58 | t = getPercentHeightSize(t); 59 | r = getPercentWidthSize(r); 60 | b = getPercentHeightSize(b); 61 | 62 | view.setPadding(l, t, r, b); 63 | } 64 | 65 | public static void autoSize(View view) 66 | { 67 | ViewGroup.LayoutParams lp = view.getLayoutParams(); 68 | 69 | if (lp == null) return; 70 | 71 | Object tag = view.getTag(R.id.id_tag_autolayout_size); 72 | if (tag != null) return; 73 | 74 | view.setTag(R.id.id_tag_autolayout_size, "Just Identify"); 75 | 76 | if (lp.width > 0) 77 | { 78 | int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth(); 79 | int designWidth = AutoLayoutConifg.getInstance().getDesignWidth(); 80 | lp.width = (int) (lp.width * 1.0f / designWidth * screenWidth); 81 | } 82 | 83 | if (lp.height > 0) 84 | { 85 | int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight(); 86 | int designHeight = AutoLayoutConifg.getInstance().getDesignHeight(); 87 | lp.height = (int) (lp.height * 1.0f / designHeight * screenHeight); 88 | } 89 | } 90 | 91 | public static int getPercentWidthSize(int val) 92 | { 93 | int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth(); 94 | int designWidth = AutoLayoutConifg.getInstance().getDesignWidth(); 95 | 96 | return (int) (val * 1.0f / designWidth * screenWidth); 97 | } 98 | 99 | 100 | public static int getPercentWidthSizeBigger(int val) 101 | { 102 | int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth(); 103 | int designWidth = AutoLayoutConifg.getInstance().getDesignWidth(); 104 | 105 | int res = val * screenWidth; 106 | if (res % designWidth == 0) 107 | { 108 | return res / designWidth; 109 | } else 110 | { 111 | return res / designWidth + 1; 112 | } 113 | 114 | } 115 | 116 | public static int getPercentHeightSizeBigger(int val) 117 | { 118 | int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight(); 119 | int designHeight = AutoLayoutConifg.getInstance().getDesignHeight(); 120 | 121 | int res = val * screenHeight; 122 | if (res % designHeight == 0) 123 | { 124 | return res / designHeight; 125 | } else 126 | { 127 | return res / designHeight + 1; 128 | } 129 | } 130 | 131 | public static int getPercentHeightSize(int val) 132 | { 133 | int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight(); 134 | int designHeight = AutoLayoutConifg.getInstance().getDesignHeight(); 135 | 136 | return (int) (val * 1.0f / designHeight * screenHeight); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/utils/L.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.utils; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * Created by zhy on 15/11/18. 7 | */ 8 | public class L 9 | { 10 | public static boolean debug = false; 11 | private static final String TAG = "AUTO_LAYOUT"; 12 | 13 | public static void e(String msg) 14 | { 15 | if (debug) 16 | { 17 | Log.e(TAG, msg); 18 | } 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/utils/ScreenUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Point; 5 | import android.os.Build; 6 | import android.util.DisplayMetrics; 7 | import android.view.Display; 8 | import android.view.WindowManager; 9 | 10 | /** 11 | * Created by zhy on 15/12/4.
12 | * form http://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels/15699681#15699681 13 | */ 14 | public class ScreenUtils 15 | { 16 | 17 | 18 | public static int[] getScreenSize(Context context, boolean useDeviceSize) 19 | { 20 | 21 | int[] size = new int[2]; 22 | 23 | WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 24 | Display d = w.getDefaultDisplay(); 25 | DisplayMetrics metrics = new DisplayMetrics(); 26 | d.getMetrics(metrics); 27 | // since SDK_INT = 1; 28 | int widthPixels = metrics.widthPixels; 29 | int heightPixels = metrics.heightPixels; 30 | 31 | if (!useDeviceSize) 32 | { 33 | size[0] = widthPixels; 34 | size[1] = heightPixels; 35 | return size; 36 | } 37 | 38 | // includes window decorations (statusbar bar/menu bar) 39 | if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) 40 | try 41 | { 42 | widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d); 43 | heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d); 44 | } catch (Exception ignored) 45 | { 46 | } 47 | // includes window decorations (statusbar bar/menu bar) 48 | if (Build.VERSION.SDK_INT >= 17) 49 | try 50 | { 51 | Point realSize = new Point(); 52 | Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize); 53 | widthPixels = realSize.x; 54 | heightPixels = realSize.y; 55 | } catch (Exception ignored) 56 | { 57 | } 58 | size[0] = widthPixels; 59 | size[1] = heightPixels; 60 | return size; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /autolayout/src/main/java/com/zhy/autolayout/widget/MetroLayout.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Color; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.zhy.autolayout.AutoLayoutInfo; 11 | import com.zhy.autolayout.R; 12 | import com.zhy.autolayout.utils.AutoLayoutHelper; 13 | import com.zhy.autolayout.utils.AutoUtils; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | import java.util.Random; 18 | 19 | /** 20 | * Created by zhy on 15/12/10. 21 | * 22 | * //do not use 23 | */ 24 | public class MetroLayout extends ViewGroup 25 | { 26 | 27 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 28 | 29 | private static class MetroBlock 30 | { 31 | int left; 32 | int top; 33 | int width; 34 | } 35 | 36 | private List mAvailablePos = new ArrayList<>(); 37 | private int mDivider; 38 | 39 | public MetroLayout(Context context, AttributeSet attrs) 40 | { 41 | super(context, attrs); 42 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MetroLayout); 43 | mDivider = a.getDimensionPixelOffset(R.styleable.MetroLayout_metro_divider, 0); 44 | mDivider = AutoUtils.getPercentWidthSizeBigger(mDivider); 45 | a.recycle(); 46 | 47 | } 48 | 49 | @Override 50 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 51 | { 52 | 53 | if (true) 54 | randomColor(); 55 | 56 | if (!isInEditMode()) 57 | mHelper.adjustChildren(); 58 | 59 | measureChildren(widthMeasureSpec, heightMeasureSpec); 60 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 61 | 62 | } 63 | 64 | private void randomColor() 65 | { 66 | Random r = new Random(255); 67 | 68 | for (int i = 0, n = getChildCount(); i < n; i++) 69 | { 70 | View v = getChildAt(i); 71 | 72 | v.setBackgroundColor(Color.argb(100, r.nextInt(), r.nextInt(), r.nextInt())); 73 | } 74 | } 75 | 76 | 77 | @Override 78 | protected void onLayout(boolean changed, int l, int t, int r, int b) 79 | { 80 | 81 | initAvailablePosition(); 82 | 83 | int left = 0; 84 | int top = 0; 85 | int divider = mDivider; 86 | 87 | for (int i = 0, n = getChildCount(); i < n; i++) 88 | { 89 | View v = getChildAt(i); 90 | if (v.getVisibility() == View.GONE) continue; 91 | 92 | MetroBlock newPos = findAvailablePos(v); 93 | left = newPos.left; 94 | top = newPos.top; 95 | 96 | int childWidth = v.getMeasuredWidth(); 97 | int childHeight = v.getMeasuredHeight(); 98 | 99 | int right = left + childWidth; 100 | int bottom = top + childHeight; 101 | 102 | v.layout(left, top, right, bottom); 103 | 104 | if (childWidth + divider < newPos.width) 105 | { 106 | newPos.left += childWidth + divider; 107 | newPos.width -= childWidth + divider; 108 | } else 109 | { 110 | mAvailablePos.remove(newPos); 111 | } 112 | 113 | MetroBlock p = new MetroBlock(); 114 | p.left = left; 115 | p.top = bottom + divider; 116 | p.width = childWidth; 117 | mAvailablePos.add(p); 118 | 119 | mergeAvailablePosition(); 120 | 121 | } 122 | } 123 | 124 | private void mergeAvailablePosition() 125 | { 126 | if (mAvailablePos.size() <= 1) return; 127 | 128 | List needRemoveBlocks = new ArrayList<>(); 129 | 130 | MetroBlock one = mAvailablePos.get(0); 131 | MetroBlock two = mAvailablePos.get(1); 132 | 133 | for (int i = 1, n = mAvailablePos.size(); i < n - 1; i++) 134 | { 135 | if (one.top == two.top) 136 | { 137 | one.width = one.width + two.width; 138 | needRemoveBlocks.add(one); 139 | two.left = one.left; 140 | two = mAvailablePos.get(i + 1); 141 | } else 142 | { 143 | one = mAvailablePos.get(i); 144 | two = mAvailablePos.get(i + 1); 145 | } 146 | } 147 | 148 | mAvailablePos.removeAll(needRemoveBlocks); 149 | 150 | } 151 | 152 | private void initAvailablePosition() 153 | { 154 | mAvailablePos.clear(); 155 | MetroBlock first = new MetroBlock(); 156 | first.left = getPaddingLeft(); 157 | first.top = getPaddingTop(); 158 | first.width = getMeasuredWidth(); 159 | mAvailablePos.add(first); 160 | } 161 | 162 | private MetroBlock findAvailablePos(View view) 163 | { 164 | MetroBlock p = new MetroBlock(); 165 | if (mAvailablePos.size() == 0) 166 | { 167 | p.left = getPaddingLeft(); 168 | p.top = getPaddingTop(); 169 | p.width = getMeasuredWidth(); 170 | return p; 171 | } 172 | int min = mAvailablePos.get(0).top; 173 | MetroBlock minHeightPos = mAvailablePos.get(0); 174 | for (MetroBlock _p : mAvailablePos) 175 | { 176 | if (_p.top < min) 177 | { 178 | min = _p.top; 179 | minHeightPos = _p; 180 | } 181 | } 182 | return minHeightPos; 183 | } 184 | 185 | 186 | @Override 187 | public MetroLayout.LayoutParams generateLayoutParams(AttributeSet attrs) 188 | { 189 | return new LayoutParams(getContext(), attrs); 190 | } 191 | 192 | public static class LayoutParams extends ViewGroup.MarginLayoutParams 193 | implements AutoLayoutHelper.AutoLayoutParams 194 | { 195 | private AutoLayoutInfo mAutoLayoutInfo; 196 | 197 | public LayoutParams(Context c, AttributeSet attrs) 198 | { 199 | super(c, attrs); 200 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); 201 | } 202 | 203 | public LayoutParams(int width, int height) 204 | { 205 | super(width, height); 206 | } 207 | 208 | public LayoutParams(ViewGroup.LayoutParams source) 209 | { 210 | super(source); 211 | } 212 | 213 | public LayoutParams(MarginLayoutParams source) 214 | { 215 | super(source); 216 | } 217 | 218 | public LayoutParams(LayoutParams source) 219 | { 220 | this((ViewGroup.LayoutParams) source); 221 | mAutoLayoutInfo = source.mAutoLayoutInfo; 222 | } 223 | 224 | @Override 225 | public AutoLayoutInfo getAutoLayoutInfo() 226 | { 227 | return mAutoLayoutInfo; 228 | } 229 | 230 | 231 | } 232 | 233 | } 234 | -------------------------------------------------------------------------------- /autolayout/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /autolayout/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /autolayout/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | autolayout 3 | 4 | -------------------------------------------------------------------------------- /autolayout_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/autolayout_01.png -------------------------------------------------------------------------------- /autolayout_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/autolayout_02.png -------------------------------------------------------------------------------- /autolayout_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/autolayout_03.png -------------------------------------------------------------------------------- /autolayout_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/autolayout_04.png -------------------------------------------------------------------------------- /autolayout_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/autolayout_06.png -------------------------------------------------------------------------------- /autolayout_07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/autolayout_07.png -------------------------------------------------------------------------------- /autolayout_08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/autolayout_08.png -------------------------------------------------------------------------------- /autolayout_09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/autolayout_09.png -------------------------------------------------------------------------------- /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.2.3' 9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' 10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /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/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Nov 19 16:52:41 GMT+08:00 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.2.1-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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /preview/preview_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/preview/preview_01.png -------------------------------------------------------------------------------- /preview/preview_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/preview/preview_02.png -------------------------------------------------------------------------------- /preview/preview_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/preview/preview_03.png -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.zhy.sample" 9 | minSdkVersion 10 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 fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:23.1.0' 25 | compile project(':autolayout') 26 | compile 'com.android.support:design:23.1.0' 27 | compile 'com.android.support:cardview-v7:23.1.0' 28 | } 29 | -------------------------------------------------------------------------------- /sample/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/zhy/android/sdk/android-sdk-macosx/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 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/zhy/sample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zhy.sample; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase 10 | { 11 | public ApplicationTest() 12 | { 13 | super(Application.class); 14 | } 15 | } -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /sample/src/main/java/com/zhy/sample/CategoryActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhy.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.TabLayout; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v4.app.FragmentPagerAdapter; 7 | import android.support.v4.view.ViewPager; 8 | 9 | import com.zhy.autolayout.AutoLayoutActivity; 10 | import com.zhy.sample.fragment.SimpleFragment; 11 | 12 | public class CategoryActivity extends AutoLayoutActivity 13 | { 14 | 15 | private TabLayout mTabLayout; 16 | private ViewPager mViewPager; 17 | 18 | private String[] mTabTitles = new String[] 19 | {"单个UI", "正方形"}; 20 | 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) 24 | { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_category); 27 | 28 | 29 | mTabLayout = (TabLayout) findViewById(R.id.id_tablayout); 30 | mViewPager = (ViewPager) findViewById(R.id.id_viewpager); 31 | 32 | mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) 33 | { 34 | @Override 35 | public Fragment getItem(int i) 36 | { 37 | return new SimpleFragment(); 38 | } 39 | 40 | @Override 41 | public CharSequence getPageTitle(int position) 42 | { 43 | 44 | return mTabTitles[position]; 45 | } 46 | 47 | @Override 48 | public int getCount() 49 | { 50 | return mTabTitles.length; 51 | } 52 | }); 53 | 54 | 55 | mTabLayout.setupWithViewPager(mViewPager); 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /sample/src/main/java/com/zhy/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhy.sample; 2 | 3 | import android.os.Build.VERSION; 4 | import android.os.Build.VERSION_CODES; 5 | import android.os.Bundle; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.app.FragmentManager; 8 | import android.support.v4.app.FragmentPagerAdapter; 9 | import android.support.v4.view.ViewPager; 10 | import android.view.Menu; 11 | import android.view.WindowManager; 12 | 13 | import com.zhy.autolayout.AutoLayoutActivity; 14 | import com.zhy.sample.fragment.ListFragment; 15 | import com.zhy.sample.fragment.PayFragment; 16 | import com.zhy.sample.fragment.RegisterFragment; 17 | 18 | import java.util.ArrayList; 19 | 20 | public class MainActivity extends AutoLayoutActivity 21 | { 22 | 23 | private ViewPager mViewPager; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | //requestWindowFeature(Window.FEATURE_NO_TITLE); 29 | setImmersionStatus(); 30 | setContentView(R.layout.activity_main); 31 | 32 | 33 | initView(); 34 | initDatas(); 35 | } 36 | 37 | private void setImmersionStatus() { 38 | if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { 39 | // 透明状态栏 40 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 41 | // 透明导航栏 42 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 43 | } 44 | } 45 | 46 | private void initDatas() { 47 | ArrayList mList = new ArrayList(); 48 | mList.add(new ListFragment()); 49 | mList.add(new RegisterFragment()); 50 | mList.add(new PayFragment()); 51 | mViewPager.setAdapter(new MyAdapter(getSupportFragmentManager(), mList)); 52 | } 53 | 54 | private void initView() { 55 | mViewPager = (ViewPager) findViewById(R.id.id_viewpager); 56 | } 57 | 58 | @Override 59 | public boolean onCreateOptionsMenu(Menu menu) 60 | { 61 | // Inflate the menu; this adds items to the action bar if it is present. 62 | getMenuInflater().inflate(R.menu.menu_main, menu); 63 | return true; 64 | } 65 | 66 | 67 | public class MyAdapter extends FragmentPagerAdapter { 68 | ArrayList tabs = null; 69 | 70 | public MyAdapter(FragmentManager fm, ArrayList tabs) { 71 | super(fm); 72 | this.tabs = tabs; 73 | } 74 | 75 | @Override 76 | public Fragment getItem(int pos) { 77 | return tabs.get(pos); 78 | } 79 | 80 | @Override 81 | public int getCount() { 82 | return tabs.size(); 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /sample/src/main/java/com/zhy/sample/UseDeviceSizeApplication.java: -------------------------------------------------------------------------------- 1 | package com.zhy.sample; 2 | 3 | import android.app.Application; 4 | 5 | import com.zhy.autolayout.config.AutoLayoutConifg; 6 | 7 | /** 8 | * Created by zhy on 15/12/23. 9 | */ 10 | public class UseDeviceSizeApplication extends Application 11 | { 12 | @Override 13 | public void onCreate() 14 | { 15 | super.onCreate(); 16 | AutoLayoutConifg.getInstance().useDeviceSize().init(this); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sample/src/main/java/com/zhy/sample/fragment/ListFragment.java: -------------------------------------------------------------------------------- 1 | package com.zhy.sample.fragment; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.BaseAdapter; 11 | import android.widget.ListView; 12 | 13 | import com.zhy.autolayout.utils.AutoUtils; 14 | import com.zhy.sample.R; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public class ListFragment extends Fragment 20 | { 21 | private View mView; 22 | private ListView mlistview; 23 | private List mList; 24 | private Context mContext; 25 | 26 | @Override 27 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) 28 | { 29 | mView = inflater.inflate(R.layout.fragment_list, container, false); 30 | initView(); 31 | return mView; 32 | } 33 | 34 | private void initView() 35 | { 36 | mContext = getActivity(); 37 | mlistview = (ListView) mView.findViewById(R.id.id_listview); 38 | mList = new ArrayList(); 39 | for (int i = 0; i < 50; i++) 40 | { 41 | mList.add(i + ""); 42 | } 43 | mlistview.setAdapter(new MyAdapter()); 44 | } 45 | 46 | class MyAdapter extends BaseAdapter 47 | { 48 | 49 | @Override 50 | public int getCount() 51 | { 52 | return mList.size(); 53 | } 54 | 55 | @Override 56 | public Object getItem(int arg0) 57 | { 58 | return mList.get(arg0); 59 | } 60 | 61 | @Override 62 | public long getItemId(int position) 63 | { 64 | return position; 65 | } 66 | 67 | @Override 68 | public View getView(int position, View convertView, ViewGroup parent) 69 | { 70 | ViewHolder holder = null; 71 | if (convertView == null) 72 | { 73 | holder = new ViewHolder(); 74 | convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false); 75 | convertView.setTag(holder); 76 | //对于listview,注意添加这一行,即可在item上使用高度 77 | AutoUtils.autoSize(convertView); 78 | } else 79 | { 80 | holder = (ViewHolder) convertView.getTag(); 81 | } 82 | 83 | return convertView; 84 | } 85 | 86 | } 87 | 88 | class ViewHolder 89 | { 90 | 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /sample/src/main/java/com/zhy/sample/fragment/PayFragment.java: -------------------------------------------------------------------------------- 1 | package com.zhy.sample.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.zhy.sample.R; 11 | 12 | public class PayFragment extends Fragment 13 | { 14 | 15 | @Override 16 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) 17 | { 18 | return inflater.inflate(R.layout.fragment_pay, container, false); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /sample/src/main/java/com/zhy/sample/fragment/RegisterFragment.java: -------------------------------------------------------------------------------- 1 | package com.zhy.sample.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.zhy.sample.R; 11 | 12 | public class RegisterFragment extends Fragment { 13 | 14 | @Override 15 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 16 | return inflater.inflate(R.layout.fragment_register, container,false); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /sample/src/main/java/com/zhy/sample/fragment/SimpleFragment.java: -------------------------------------------------------------------------------- 1 | package com.zhy.sample.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.zhy.sample.R; 11 | 12 | public class SimpleFragment extends Fragment 13 | { 14 | 15 | @Nullable 16 | @Override 17 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 18 | { 19 | return inflater.inflate(R.layout.activity_main, container, false); 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /sample/src/main/java/com/zhy/sample/view/AutoCardView.java: -------------------------------------------------------------------------------- 1 | package com.zhy.sample.view; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.CardView; 5 | import android.util.AttributeSet; 6 | 7 | import com.zhy.autolayout.AutoFrameLayout; 8 | import com.zhy.autolayout.utils.AutoLayoutHelper; 9 | 10 | /** 11 | * Created by zhy on 15/12/8. 12 | */ 13 | public class AutoCardView extends CardView 14 | { 15 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 16 | 17 | public AutoCardView(Context context) 18 | { 19 | super(context); 20 | } 21 | 22 | public AutoCardView(Context context, AttributeSet attrs) 23 | { 24 | super(context, attrs); 25 | } 26 | 27 | public AutoCardView(Context context, AttributeSet attrs, int defStyleAttr) 28 | { 29 | super(context, attrs, defStyleAttr); 30 | } 31 | 32 | @Override 33 | public AutoFrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) 34 | { 35 | return new AutoFrameLayout.LayoutParams(getContext(), attrs); 36 | } 37 | 38 | @Override 39 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 40 | { 41 | if (!isInEditMode()) 42 | { 43 | mHelper.adjustChildren(); 44 | } 45 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/daili_xuanzhong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/daili_xuanzhong.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/daili_yuanquan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/daili_yuanquan.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/login_dengluhao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/login_dengluhao.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/login_fanhui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/login_fanhui.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/login_miam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/login_miam.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/login_yanzhengma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/login_yanzhengma.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/login_zaicishurumima.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/login_zaicishurumima.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/wode_weixinzhifu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/wode_weixinzhifu.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/wode_zhifubaozhifu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/wode_zhifubaozhifu.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/wode_zijin_dise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-hdpi/wode_zijin_dise.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/login_dengluhao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xhdpi/login_dengluhao.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/login_miam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xhdpi/login_miam.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/login_yanzhengma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xhdpi/login_yanzhengma.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/login_zaicishurumima.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xhdpi/login_zaicishurumima.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/tuijian_dailishangpaihangbang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xhdpi/tuijian_dailishangpaihangbang.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/tuijian_pinpaituijian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xhdpi/tuijian_pinpaituijian.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/tuijian_rexiaopin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xhdpi/tuijian_rexiaopin.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/tuijian_touxiang6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xhdpi/tuijian_touxiang6.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/tuijian_xinpintuijia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xhdpi/tuijian_xinpintuijia.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/login_dengluhao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xxhdpi/login_dengluhao.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/login_fanhui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xxhdpi/login_fanhui.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/login_miam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xxhdpi/login_miam.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/login_yanzhengma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xxhdpi/login_yanzhengma.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/login_zaicishurumima.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/drawable-xxhdpi/login_zaicishurumima.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable/selector_btn_stroke_orange.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/selector_pay_radio.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/shape_btn_edge_orange.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/shape_btn_edge_orange_pre.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/shape_edit_stroke.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_category.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 19 | 20 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 16 | 17 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/app_base_title.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 19 | 26 | 27 | 36 | 37 | 44 | 45 | 56 | 57 | 65 | 66 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/fragment_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/fragment_pay.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 13 | 14 | 22 | 23 | 31 | 32 | 33 | 41 | 42 | 46 | 47 | 54 | 55 | 61 | 62 | 67 | 68 | 74 | 75 | 82 | 83 | 84 | 92 | 93 | 94 | 98 | 99 | 106 | 107 | 113 | 114 | 119 | 120 | 126 | 127 | 134 | 135 | 136 | 144 | 145 | 146 | 150 | 151 | 159 | 160 | 167 | 168 | 179 | 180 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/fragment_register.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 15 | 16 | 23 | 24 | 29 | 30 | 42 | 43 | 44 | 50 | 51 | 56 | 57 | 64 | 65 | 70 | 71 | 82 | 83 | 84 | 87 | 88 | 99 | 100 | 101 | 108 | 109 | 116 | 117 | 122 | 123 | 134 | 135 | 136 | 143 | 144 | 151 | 152 | 157 | 158 | 169 | 170 | 171 | 183 | 184 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 17 | 18 | 26 | 27 | 36 | 37 | 46 | 47 | 56 | 57 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 |

5 | 9 | 10 | 14 | 15 | 16 | 20 | 21 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu_test.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/mipmap-hdpi/add.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sample/src/main/res/values/color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ff6600 5 | #c8580d 6 | #d7d7d7 7 | #c9c9c9 8 | #c3c3c3 9 | #666666 10 | #f31216 11 | #f3f3f3 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 20px 7 | 020px 8 | 20dp 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | sample 3 | 4 | Hello world! 5 | Settings 6 | TestActivity 7 | 8 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 10 | 11 | 12 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':autolayout', ':widgetsample' 2 | -------------------------------------------------------------------------------- /widgetsample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /widgetsample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.zhy.autolayout.test.widgets" 9 | minSdkVersion 10 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 fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:23.1.0' 25 | compile project(':autolayout') 26 | } 27 | -------------------------------------------------------------------------------- /widgetsample/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/zhy/android/sdk/android-sdk-macosx/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 | -------------------------------------------------------------------------------- /widgetsample/src/androidTest/java/com/zhy/autolayout/test/widgets/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.test.widgets; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase 10 | { 11 | public ApplicationTest() 12 | { 13 | super(Application.class); 14 | } 15 | } -------------------------------------------------------------------------------- /widgetsample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /widgetsample/src/main/java/com/zhy/autolayout/test/widgets/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhy.autolayout.test.widgets; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.Menu; 6 | import android.view.MenuItem; 7 | 8 | public class MainActivity extends AppCompatActivity 9 | { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) 13 | { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | } 17 | 18 | @Override 19 | public boolean onCreateOptionsMenu(Menu menu) 20 | { 21 | // Inflate the menu; this adds items to the action bar if it is present. 22 | getMenuInflater().inflate(R.menu.menu_main, menu); 23 | return true; 24 | } 25 | 26 | @Override 27 | public boolean onOptionsItemSelected(MenuItem item) 28 | { 29 | // Handle action bar item clicks here. The action bar will 30 | // automatically handle clicks on the Home/Up button, so long 31 | // as you specify a parent activity in AndroidManifest.xml. 32 | int id = item.getItemId(); 33 | 34 | //noinspection SimplifiableIfStatement 35 | if (id == R.id.action_settings) 36 | { 37 | return true; 38 | } 39 | 40 | return super.onOptionsItemSelected(item); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /widgetsample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 15 | 16 | 21 | 22 | 23 | 28 | 29 | 34 | 35 | 40 | 41 | 46 | 47 | 52 | 53 | 58 | 59 | 64 | 65 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /widgetsample/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /widgetsample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/widgetsample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /widgetsample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/widgetsample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /widgetsample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/widgetsample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /widgetsample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JunWeiUp/AndroidAutoLayout/05a5f2d16aceafc43cab75c513b9d15cd7c09f75/widgetsample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /widgetsample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /widgetsample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /widgetsample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | widgetSample 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /widgetsample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | --------------------------------------------------------------------------------