├── .gitignore
├── 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-widget
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zhy
│ │ └── autolayout
│ │ └── widget
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── zhy
│ │ └── autolayout
│ │ └── widget
│ │ ├── AutoActionMenuItemView.java
│ │ ├── AutoCardView.java
│ │ ├── AutoLayoutWidgetActivity.java
│ │ ├── AutoRadioGroup.java
│ │ ├── AutoTabLayout.java
│ │ ├── AutoTableLayout.java
│ │ ├── AutoTableRow.java
│ │ └── AutoToolbar.java
│ └── res
│ └── values
│ ├── attrs.xml
│ └── strings.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
│ │ ├── DimenUtils.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
│ │ ├── RecyclerViewFragment.java
│ │ ├── RecyclerViewGridFragment.java
│ │ ├── RegisterFragment.java
│ │ ├── SimpleFragment.java
│ │ └── TestFragment.java
│ │ └── view
│ │ ├── AutoCardView.java
│ │ └── DividerItemDecoration.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
│ ├── activity_test.xml
│ ├── app_base_title.xml
│ ├── fragment_list.xml
│ ├── fragment_pay.xml
│ ├── fragment_recyclerview.xml
│ ├── fragment_recyclerview_grid.xml
│ ├── fragment_register.xml
│ ├── list_item.xml
│ ├── recyclerview_item.xml
│ └── recyclerview_item_grid.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
│ └── fragments
│ └── SimpleFragment.java
└── res
├── layout
├── activity_main.xml
└── fragment_simple.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 |
9 |
10 | # Generated files
11 | bin/
12 | gen/
13 |
14 | # Gradle files
15 | .gradle/
16 | /build
17 | /*/build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Eclipse project files
29 | .classpath
30 | .project
31 | .settings/
32 |
33 | # Intellij project files
34 | *.iml
35 | *.ipr
36 | *.iws
37 | .idea/
38 |
39 | # System files
40 | .DS_Store
--------------------------------------------------------------------------------
/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 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/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-widget/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/autolayout-widget/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 10
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:appcompat-v7:23.1.0'
24 | compile project(':autolayout')
25 | compile 'com.android.support:support-v4:23.1.0'
26 | compile 'com.android.support:design:23.1.1'
27 | compile 'com.android.support:gridlayout-v7:23.1.0'
28 | compile 'com.android.support:cardview-v7:23.1.0'
29 | }
30 |
--------------------------------------------------------------------------------
/autolayout-widget/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-widget/src/androidTest/java/com/zhy/autolayout/widget/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.widget;
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-widget/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/autolayout-widget/src/main/java/com/zhy/autolayout/widget/AutoActionMenuItemView.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 |
6 | import android.support.v7.view.menu.ActionMenuItemView;
7 | import android.util.AttributeSet;
8 | import android.util.TypedValue;
9 |
10 |
11 | import com.zhy.autolayout.utils.AutoUtils;
12 | import com.zhy.autolayout.utils.DimenUtils;
13 |
14 | /**
15 | * Created by hupei on 2016/3/7 14:44.
16 | */
17 | public class AutoActionMenuItemView extends ActionMenuItemView {
18 | private static final int NO_VALID = -1;
19 | private int mMenuTextSize;
20 |
21 | public AutoActionMenuItemView(Context context) {
22 | this(context, null);
23 | }
24 |
25 | public AutoActionMenuItemView(Context context, AttributeSet attrs) {
26 | this(context, attrs, 0);
27 | }
28 |
29 | public AutoActionMenuItemView(Context context, AttributeSet attrs, int defStyle) {
30 | super(context, attrs, defStyle);
31 | TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.Theme,
32 | defStyle, R.style.ThemeOverlay_AppCompat);
33 | int menuTextAppearance = a.getResourceId(R.styleable.Theme_actionBarTheme,
34 | R.style.ThemeOverlay_AppCompat_ActionBar);
35 | mMenuTextSize = loadTextSizeFromTextAppearance(menuTextAppearance);
36 | a.recycle();
37 | }
38 |
39 | @Override
40 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
41 | if (!this.isInEditMode()) {
42 | setUpTitleTextSize();
43 | }
44 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
45 | }
46 |
47 | private int loadTextSizeFromTextAppearance(int textAppearanceResId) {
48 | TypedArray a = getContext().obtainStyledAttributes(textAppearanceResId,
49 | R.styleable.TextAppearance);
50 | try {
51 | if (!DimenUtils.isPxVal(a.peekValue(R.styleable.TextAppearance_android_textSize)))
52 | return NO_VALID;
53 | return a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, NO_VALID);
54 | } finally {
55 | a.recycle();
56 | }
57 | }
58 |
59 | private void setUpTitleTextSize() {
60 | if (mMenuTextSize == -1) return;
61 | int autoTextSize = AutoUtils.getPercentHeightSize(mMenuTextSize);
62 | setTextSize(TypedValue.COMPLEX_UNIT_PX, autoTextSize);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/autolayout-widget/src/main/java/com/zhy/autolayout/widget/AutoCardView.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.widget;
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 |
--------------------------------------------------------------------------------
/autolayout-widget/src/main/java/com/zhy/autolayout/widget/AutoLayoutWidgetActivity.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 |
7 | import com.zhy.autolayout.AutoLayoutActivity;
8 |
9 | /**
10 | * Created by hupei on 2016/3/7 16:44.
11 | */
12 | public class AutoLayoutWidgetActivity extends AutoLayoutActivity {
13 |
14 | private static final String ACTION_MENU_ITEM_VIEW = "android.support.v7.view.menu.ActionMenuItemView";
15 | private static final String TAB_LAYOUT = "android.support.design.widget.TabLayout";
16 |
17 | @Override
18 | public View onCreateView(String name, Context context, AttributeSet attrs) {
19 | View view = null;
20 |
21 | if (name.equals(ACTION_MENU_ITEM_VIEW)) {
22 | view = new AutoActionMenuItemView(context, attrs);
23 | }
24 | if (name.equals(TAB_LAYOUT)) {
25 | view = new AutoTabLayout(context, attrs);
26 | }
27 |
28 | if (view != null) return view;
29 | return super.onCreateView(name, context, attrs);
30 | }
31 | }
--------------------------------------------------------------------------------
/autolayout-widget/src/main/java/com/zhy/autolayout/widget/AutoRadioGroup.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.ViewGroup;
6 | import android.widget.RadioGroup;
7 |
8 | import com.zhy.autolayout.AutoLayoutInfo;
9 | import com.zhy.autolayout.utils.AutoLayoutHelper;
10 |
11 | /**
12 | * Created by hupei on 2016/2/29 9:59.
13 | */
14 | public class AutoRadioGroup extends RadioGroup
15 | {
16 | private AutoLayoutHelper mHelper = new AutoLayoutHelper(this);
17 |
18 | public AutoRadioGroup(Context context)
19 | {
20 | super(context);
21 | }
22 |
23 | public AutoRadioGroup(Context context, AttributeSet attrs)
24 | {
25 | super(context, attrs);
26 | }
27 |
28 |
29 | @Override
30 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
31 | {
32 | if (!isInEditMode())
33 | mHelper.adjustChildren();
34 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
35 | }
36 |
37 | @Override
38 | protected void onLayout(boolean changed, int l, int t, int r, int b)
39 | {
40 | super.onLayout(changed, l, t, r, b);
41 | }
42 |
43 | @Override
44 | public LayoutParams generateLayoutParams(AttributeSet attrs)
45 | {
46 | return new LayoutParams(getContext(), attrs);
47 | }
48 |
49 | public static class LayoutParams extends RadioGroup.LayoutParams
50 | implements AutoLayoutHelper.AutoLayoutParams
51 | {
52 | private AutoLayoutInfo mAutoLayoutInfo;
53 |
54 | public LayoutParams(Context c, AttributeSet attrs)
55 | {
56 | super(c, attrs);
57 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs);
58 | }
59 |
60 | @Override
61 | public AutoLayoutInfo getAutoLayoutInfo()
62 | {
63 | return mAutoLayoutInfo;
64 | }
65 |
66 |
67 | public LayoutParams(int width, int height)
68 | {
69 | super(width, height);
70 | }
71 |
72 | public LayoutParams(ViewGroup.LayoutParams source)
73 | {
74 | super(source);
75 | }
76 |
77 | public LayoutParams(MarginLayoutParams source)
78 | {
79 | super(source);
80 | }
81 |
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/autolayout-widget/src/main/java/com/zhy/autolayout/widget/AutoTabLayout.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.support.design.widget.TabLayout;
6 | import android.util.AttributeSet;
7 | import android.util.TypedValue;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import com.zhy.autolayout.utils.AutoUtils;
12 | import com.zhy.autolayout.utils.DimenUtils;
13 |
14 | /**
15 | * Created by zhy on 16/3/3.
16 | */
17 | public class AutoTabLayout extends TabLayout
18 | {
19 | private static final int NO_VALID = -1;
20 | private int mTextSize;
21 | private boolean mTextSizeBaseWidth = false;
22 |
23 | public AutoTabLayout(Context context)
24 | {
25 | this(context, null);
26 | }
27 |
28 | public AutoTabLayout(Context context, AttributeSet attrs)
29 | {
30 | this(context, attrs, 0);
31 | }
32 |
33 | public AutoTabLayout(Context context, AttributeSet attrs, int defStyleAttr)
34 | {
35 | super(context, attrs, defStyleAttr);
36 |
37 | initTextSizeBaseWidth(context, attrs);
38 |
39 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout,
40 | defStyleAttr, R.style.Widget_Design_TabLayout);
41 | int tabTextAppearance = a.getResourceId(R.styleable.TabLayout_tabTextAppearance,
42 | R.style.TextAppearance_Design_Tab);
43 |
44 | mTextSize = loadTextSizeFromTextAppearance(tabTextAppearance);
45 | a.recycle();
46 | }
47 |
48 | private void initTextSizeBaseWidth(Context context, AttributeSet attrs)
49 | {
50 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoTabLayout);
51 | mTextSizeBaseWidth = a.getBoolean(R.styleable.AutoTabLayout_auto_textSize_base_width, false);
52 | a.recycle();
53 | }
54 |
55 | private int loadTextSizeFromTextAppearance(int textAppearanceResId)
56 | {
57 | TypedArray a = getContext().obtainStyledAttributes(textAppearanceResId,
58 | R.styleable.TextAppearance);
59 |
60 | try
61 | {
62 | if (!DimenUtils.isPxVal(a.peekValue(R.styleable.TextAppearance_android_textSize)))
63 | return NO_VALID;
64 | return a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, NO_VALID);
65 | } finally
66 | {
67 | a.recycle();
68 | }
69 | }
70 |
71 | @Override
72 | public void addTab(Tab tab, int position, boolean setSelected)
73 | {
74 | super.addTab(tab, position, setSelected);
75 | setUpTabTextSize(tab);
76 | }
77 |
78 | @Override
79 | public void addTab(Tab tab, boolean setSelected)
80 | {
81 | super.addTab(tab, setSelected);
82 | setUpTabTextSize(tab);
83 | }
84 |
85 | private void setUpTabTextSize(Tab tab)
86 | {
87 | if (mTextSize == NO_VALID || tab.getCustomView() != null) return;
88 |
89 | ViewGroup tabGroup = (ViewGroup) getChildAt(0);
90 | ViewGroup tabContainer = (ViewGroup) tabGroup.getChildAt(tab.getPosition());
91 | TextView textView = (TextView) tabContainer.getChildAt(1);
92 |
93 |
94 | if (AutoUtils.autoed(textView))
95 | {
96 | return;
97 | }
98 | int autoTextSize = 0 ;
99 | if (mTextSizeBaseWidth)
100 | {
101 | autoTextSize = AutoUtils.getPercentWidthSize(mTextSize);
102 | } else
103 | {
104 | autoTextSize = AutoUtils.getPercentHeightSize(mTextSize);
105 | }
106 |
107 |
108 | textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, autoTextSize);
109 | }
110 |
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/autolayout-widget/src/main/java/com/zhy/autolayout/widget/AutoTableLayout.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.ViewGroup;
6 | import android.widget.TableLayout;
7 |
8 | import com.zhy.autolayout.AutoLayoutInfo;
9 | import com.zhy.autolayout.utils.AutoLayoutHelper;
10 |
11 | /**
12 | * Created by hupei on 2016/2/29 9:59.
13 | */
14 | public class AutoTableLayout extends TableLayout
15 | {
16 | private AutoLayoutHelper mHelper = new AutoLayoutHelper(this);
17 |
18 | public AutoTableLayout(Context context)
19 | {
20 | super(context);
21 | }
22 |
23 | public AutoTableLayout(Context context, AttributeSet attrs)
24 | {
25 | super(context, attrs);
26 | }
27 |
28 | @Override
29 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
30 | {
31 | if (!isInEditMode())
32 | mHelper.adjustChildren();
33 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
34 | }
35 |
36 |
37 | @Override
38 | protected void onLayout(boolean changed, int l, int t, int r, int b)
39 | {
40 | super.onLayout(changed, l, t, r, b);
41 | }
42 |
43 |
44 | @Override
45 | public LayoutParams generateLayoutParams(AttributeSet attrs)
46 | {
47 | return new LayoutParams(getContext(), attrs);
48 | }
49 |
50 |
51 | public static class LayoutParams extends TableLayout.LayoutParams
52 | implements AutoLayoutHelper.AutoLayoutParams
53 | {
54 | private AutoLayoutInfo mAutoLayoutInfo;
55 |
56 | public LayoutParams(Context c, AttributeSet attrs)
57 | {
58 | super(c, attrs);
59 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs);
60 | }
61 |
62 | @Override
63 | public AutoLayoutInfo getAutoLayoutInfo()
64 | {
65 | return mAutoLayoutInfo;
66 | }
67 |
68 |
69 | public LayoutParams(int width, int height)
70 | {
71 | super(width, height);
72 | }
73 |
74 |
75 | public LayoutParams(ViewGroup.LayoutParams source)
76 | {
77 | super(source);
78 | }
79 |
80 | public LayoutParams(MarginLayoutParams source)
81 | {
82 | super(source);
83 | }
84 |
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/autolayout-widget/src/main/java/com/zhy/autolayout/widget/AutoTableRow.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.ViewGroup;
6 | import android.widget.TableRow;
7 |
8 | import com.zhy.autolayout.AutoLayoutInfo;
9 | import com.zhy.autolayout.utils.AutoLayoutHelper;
10 |
11 | /**
12 | * Created by hupei on 2016/2/29 9:59.
13 | */
14 | public class AutoTableRow extends TableRow
15 | {
16 | private AutoLayoutHelper mHelper = new AutoLayoutHelper(this);
17 |
18 | public AutoTableRow(Context context)
19 | {
20 | super(context);
21 | }
22 |
23 | public AutoTableRow(Context context, AttributeSet attrs)
24 | {
25 | super(context, attrs);
26 | }
27 |
28 |
29 | @Override
30 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
31 | {
32 | if (!isInEditMode())
33 | mHelper.adjustChildren();
34 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
35 | }
36 |
37 |
38 | @Override
39 | protected void onLayout(boolean changed, int l, int t, int r, int b)
40 | {
41 | super.onLayout(changed, l, t, r, b);
42 | }
43 |
44 |
45 | @Override
46 | public LayoutParams generateLayoutParams(AttributeSet attrs)
47 | {
48 | return new LayoutParams(getContext(), attrs);
49 | }
50 |
51 |
52 | public static class LayoutParams extends TableRow.LayoutParams
53 | implements AutoLayoutHelper.AutoLayoutParams
54 | {
55 | private AutoLayoutInfo mAutoLayoutInfo;
56 |
57 | public LayoutParams(Context c, AttributeSet attrs)
58 | {
59 | super(c, attrs);
60 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs);
61 | }
62 |
63 | @Override
64 | public AutoLayoutInfo getAutoLayoutInfo()
65 | {
66 | return mAutoLayoutInfo;
67 | }
68 |
69 |
70 | public LayoutParams(int width, int height)
71 | {
72 | super(width, height);
73 | }
74 |
75 |
76 | public LayoutParams(ViewGroup.LayoutParams source)
77 | {
78 | super(source);
79 | }
80 |
81 | public LayoutParams(MarginLayoutParams source)
82 | {
83 | super(source);
84 | }
85 |
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/autolayout-widget/src/main/java/com/zhy/autolayout/widget/AutoToolbar.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.support.v7.widget.Toolbar;
6 | import android.text.TextUtils;
7 | import android.util.AttributeSet;
8 | import android.util.TypedValue;
9 | import android.widget.TextView;
10 |
11 | import com.zhy.autolayout.AutoLayoutInfo;
12 | import com.zhy.autolayout.utils.AutoLayoutHelper;
13 | import com.zhy.autolayout.utils.AutoUtils;
14 | import com.zhy.autolayout.utils.DimenUtils;
15 |
16 | import java.lang.reflect.Field;
17 |
18 | /**
19 | * Created by hupei on 2015/12/28 20:33.
20 | */
21 | public class AutoToolbar extends Toolbar {
22 | private static final int NO_VALID = -1;
23 | private int mTextSize;
24 | private int mSubTextSize;
25 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this);
26 |
27 | public AutoToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
28 | super(context, attrs, defStyleAttr);
29 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Toolbar,
30 | defStyleAttr, R.style.Widget_AppCompat_Toolbar);
31 |
32 | int titleTextAppearance = a.getResourceId(R.styleable.Toolbar_titleTextAppearance,
33 | R.style.TextAppearance_Widget_AppCompat_Toolbar_Title);
34 |
35 | int subtitleTextAppearance = a.getResourceId(R.styleable.Toolbar_subtitleTextAppearance,
36 | R.style.TextAppearance_Widget_AppCompat_Toolbar_Subtitle);
37 |
38 | mTextSize = loadTextSizeFromTextAppearance(titleTextAppearance);
39 | mSubTextSize = loadTextSizeFromTextAppearance(subtitleTextAppearance);
40 |
41 | TypedArray menuA = context.getTheme().obtainStyledAttributes(attrs, R.styleable.Theme,
42 | defStyleAttr, R.style.ThemeOverlay_AppCompat);
43 | int menuTextAppearance = menuA.getResourceId(R.styleable.Theme_actionBarTheme,
44 | R.style.ThemeOverlay_AppCompat_ActionBar);
45 | int menuTextSize = loadTextSizeFromTextAppearance(menuTextAppearance);
46 |
47 | //防止 menu 定义 textSize,而 Toolbar 无定义 textSize 时,title 的 textSize 随 menu 变化
48 | if (mTextSize == NO_VALID) mTextSize = menuTextSize;
49 | if (mSubTextSize == NO_VALID) mSubTextSize = menuTextSize;
50 |
51 | a.recycle();
52 | menuA.recycle();
53 | }
54 |
55 | public AutoToolbar(Context context, AttributeSet attrs) {
56 | this(context, attrs, 0);
57 | }
58 |
59 | public AutoToolbar(Context context) {
60 | this(context, null);
61 | }
62 |
63 | private int loadTextSizeFromTextAppearance(int textAppearanceResId) {
64 | TypedArray a = getContext().obtainStyledAttributes(textAppearanceResId,
65 | R.styleable.TextAppearance);
66 | try {
67 | if (!DimenUtils.isPxVal(a.peekValue(R.styleable.TextAppearance_android_textSize)))
68 | return NO_VALID;
69 | return a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, NO_VALID);
70 | } finally {
71 | a.recycle();
72 | }
73 | }
74 |
75 | private void setUpTitleTextSize() {
76 | CharSequence title = getTitle();
77 | if (!TextUtils.isEmpty(title) && mTextSize != NO_VALID)
78 | setUpTitleTextSize("mTitleTextView", mTextSize);
79 | CharSequence subtitle = getSubtitle();
80 | if (!TextUtils.isEmpty(subtitle) && mSubTextSize != NO_VALID)
81 | setUpTitleTextSize("mSubtitleTextView", mSubTextSize);
82 | }
83 |
84 | private void setUpTitleTextSize(String name, int val) {
85 | try {
86 | //反射 Toolbar 的 TextView
87 | Field f = getClass().getSuperclass().getDeclaredField(name);
88 | f.setAccessible(true);
89 | TextView textView = (TextView) f.get(this);
90 | if (textView != null) {
91 | int autoTextSize = AutoUtils.getPercentHeightSize(val);
92 | textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, autoTextSize);
93 | }
94 | } catch (Exception e) {
95 | e.printStackTrace();
96 | }
97 | }
98 |
99 | @Override
100 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
101 | if (!this.isInEditMode()) {
102 | setUpTitleTextSize();
103 | this.mHelper.adjustChildren();
104 | }
105 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
106 | }
107 |
108 | @Override
109 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
110 | super.onLayout(changed, l, t, r, b);
111 | }
112 |
113 | @Override
114 | public LayoutParams generateLayoutParams(AttributeSet attrs) {
115 | return new LayoutParams(this.getContext(), attrs);
116 | }
117 |
118 | public static class LayoutParams extends Toolbar.LayoutParams implements AutoLayoutHelper.AutoLayoutParams {
119 | private AutoLayoutInfo mDimenLayoutInfo;
120 |
121 | public LayoutParams(Context c, AttributeSet attrs) {
122 | super(c, attrs);
123 | this.mDimenLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs);
124 | }
125 |
126 | @Override
127 | public AutoLayoutInfo getAutoLayoutInfo() {
128 | return this.mDimenLayoutInfo;
129 | }
130 |
131 | public LayoutParams(int width, int height) {
132 | super(width, height);
133 | }
134 |
135 | public LayoutParams(android.view.ViewGroup.LayoutParams source) {
136 | super(source);
137 | }
138 |
139 | public LayoutParams(MarginLayoutParams source) {
140 | super(source);
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/autolayout-widget/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/autolayout-widget/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | autolayout-widget
3 |
4 |
--------------------------------------------------------------------------------
/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.4.5"
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 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/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 | import android.view.ViewGroup;
5 | import android.widget.TextView;
6 |
7 | import com.zhy.autolayout.attr.Attrs;
8 | import com.zhy.autolayout.attr.AutoAttr;
9 | import com.zhy.autolayout.attr.HeightAttr;
10 | import com.zhy.autolayout.attr.MarginBottomAttr;
11 | import com.zhy.autolayout.attr.MarginLeftAttr;
12 | import com.zhy.autolayout.attr.MarginRightAttr;
13 | import com.zhy.autolayout.attr.MarginTopAttr;
14 | import com.zhy.autolayout.attr.MaxHeightAttr;
15 | import com.zhy.autolayout.attr.MaxWidthAttr;
16 | import com.zhy.autolayout.attr.MinHeightAttr;
17 | import com.zhy.autolayout.attr.MinWidthAttr;
18 | import com.zhy.autolayout.attr.PaddingBottomAttr;
19 | import com.zhy.autolayout.attr.PaddingLeftAttr;
20 | import com.zhy.autolayout.attr.PaddingRightAttr;
21 | import com.zhy.autolayout.attr.PaddingTopAttr;
22 | import com.zhy.autolayout.attr.TextSizeAttr;
23 | import com.zhy.autolayout.attr.WidthAttr;
24 |
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 | public class AutoLayoutInfo
29 | {
30 | private List autoAttrs = new ArrayList<>();
31 |
32 | public void addAttr(AutoAttr autoAttr)
33 | {
34 | autoAttrs.add(autoAttr);
35 | }
36 |
37 |
38 | public void fillAttrs(View view)
39 | {
40 | for (AutoAttr autoAttr : autoAttrs)
41 | {
42 | autoAttr.apply(view);
43 | }
44 | }
45 |
46 |
47 | public static AutoLayoutInfo getAttrFromView(View view, int attrs, int base)
48 | {
49 | ViewGroup.LayoutParams params = view.getLayoutParams();
50 | if (params == null) return null;
51 | AutoLayoutInfo autoLayoutInfo = new AutoLayoutInfo();
52 |
53 | // width & height
54 | if ((attrs & Attrs.WIDTH) != 0 && params.width > 0)
55 | {
56 | autoLayoutInfo.addAttr(WidthAttr.generate(params.width, base));
57 | }
58 |
59 | if ((attrs & Attrs.HEIGHT) != 0 && params.height > 0)
60 | {
61 | autoLayoutInfo.addAttr(HeightAttr.generate(params.height, base));
62 | }
63 |
64 | //margin
65 | if (params instanceof ViewGroup.MarginLayoutParams)
66 | {
67 | if ((attrs & Attrs.MARGIN) != 0)
68 | {
69 | autoLayoutInfo.addAttr(MarginLeftAttr.generate(((ViewGroup.MarginLayoutParams) params).leftMargin, base));
70 | autoLayoutInfo.addAttr(MarginTopAttr.generate(((ViewGroup.MarginLayoutParams) params).topMargin, base));
71 | autoLayoutInfo.addAttr(MarginRightAttr.generate(((ViewGroup.MarginLayoutParams) params).rightMargin, base));
72 | autoLayoutInfo.addAttr(MarginBottomAttr.generate(((ViewGroup.MarginLayoutParams) params).bottomMargin, base));
73 | }
74 | if ((attrs & Attrs.MARGIN_LEFT) != 0)
75 | {
76 | autoLayoutInfo.addAttr(MarginLeftAttr.generate(((ViewGroup.MarginLayoutParams) params).leftMargin, base));
77 | }
78 | if ((attrs & Attrs.MARGIN_TOP) != 0)
79 | {
80 | autoLayoutInfo.addAttr(MarginTopAttr.generate(((ViewGroup.MarginLayoutParams) params).topMargin, base));
81 | }
82 | if ((attrs & Attrs.MARGIN_RIGHT) != 0)
83 | {
84 | autoLayoutInfo.addAttr(MarginRightAttr.generate(((ViewGroup.MarginLayoutParams) params).rightMargin, base));
85 | }
86 | if ((attrs & Attrs.MARGIN_BOTTOM) != 0)
87 | {
88 | autoLayoutInfo.addAttr(MarginBottomAttr.generate(((ViewGroup.MarginLayoutParams) params).bottomMargin, base));
89 | }
90 | }
91 |
92 | //padding
93 | if ((attrs & Attrs.PADDING) != 0)
94 | {
95 | autoLayoutInfo.addAttr(PaddingLeftAttr.generate(view.getPaddingLeft(), base));
96 | autoLayoutInfo.addAttr(PaddingTopAttr.generate(view.getPaddingTop(), base));
97 | autoLayoutInfo.addAttr(PaddingRightAttr.generate(view.getPaddingRight(), base));
98 | autoLayoutInfo.addAttr(PaddingBottomAttr.generate(view.getPaddingBottom(), base));
99 | }
100 | if ((attrs & Attrs.PADDING_LEFT) != 0)
101 | {
102 | autoLayoutInfo.addAttr(MarginLeftAttr.generate(view.getPaddingLeft(), base));
103 | }
104 | if ((attrs & Attrs.PADDING_TOP) != 0)
105 | {
106 | autoLayoutInfo.addAttr(MarginTopAttr.generate(view.getPaddingTop(), base));
107 | }
108 | if ((attrs & Attrs.PADDING_RIGHT) != 0)
109 | {
110 | autoLayoutInfo.addAttr(MarginRightAttr.generate(view.getPaddingRight(), base));
111 | }
112 | if ((attrs & Attrs.PADDING_BOTTOM) != 0)
113 | {
114 | autoLayoutInfo.addAttr(MarginBottomAttr.generate(view.getPaddingBottom(), base));
115 | }
116 |
117 | //minWidth ,maxWidth , minHeight , maxHeight
118 | if ((attrs & Attrs.MIN_WIDTH) != 0)
119 | {
120 | autoLayoutInfo.addAttr(MinWidthAttr.generate(MinWidthAttr.getMinWidth(view), base));
121 | }
122 | if ((attrs & Attrs.MAX_WIDTH) != 0)
123 | {
124 | autoLayoutInfo.addAttr(MaxWidthAttr.generate(MaxWidthAttr.getMaxWidth(view), base));
125 | }
126 | if ((attrs & Attrs.MIN_HEIGHT) != 0)
127 | {
128 | autoLayoutInfo.addAttr(MinHeightAttr.generate(MinHeightAttr.getMinHeight(view), base));
129 | }
130 | if ((attrs & Attrs.MAX_HEIGHT) != 0)
131 | {
132 | autoLayoutInfo.addAttr(MaxHeightAttr.generate(MaxHeightAttr.getMaxHeight(view), base));
133 | }
134 |
135 | //textsize
136 |
137 | if (view instanceof TextView)
138 | {
139 | if ((attrs & Attrs.TEXTSIZE) != 0)
140 | {
141 | autoLayoutInfo.addAttr(TextSizeAttr.generate((int) ((TextView) view).getTextSize(), base));
142 | }
143 | }
144 | return autoLayoutInfo;
145 | }
146 |
147 |
148 | @Override
149 | public String toString()
150 | {
151 | return "AutoLayoutInfo{" +
152 | "autoAttrs=" + autoAttrs +
153 | '}';
154 | }
155 | }
--------------------------------------------------------------------------------
/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 | public static final int BASE_WIDTH = 1;
15 | public static final int BASE_HEIGHT = 2;
16 | public static final int BASE_DEFAULT = 3;
17 |
18 | protected int pxVal;
19 | protected int baseWidth;
20 | protected int baseHeight;
21 |
22 | /*
23 | protected boolean isBaseWidth;
24 | protected boolean isBaseDefault;
25 |
26 | public AutoAttr(int pxVal)
27 | {
28 | this.pxVal = pxVal;
29 | isBaseDefault = true;
30 | }
31 |
32 | public AutoAttr(int pxVal, boolean isBaseWidth)
33 | {
34 | this.pxVal = pxVal;
35 | this.isBaseWidth = isBaseWidth;
36 | }
37 | */
38 |
39 | public AutoAttr(int pxVal, int baseWidth, int baseHeight)
40 | {
41 | this.pxVal = pxVal;
42 | this.baseWidth = baseWidth;
43 | this.baseHeight = baseHeight;
44 | }
45 |
46 | public void apply(View view)
47 | {
48 |
49 | boolean log = view.getTag() != null && view.getTag().toString().equals("auto");
50 |
51 | if (log)
52 | {
53 | L.e(" pxVal = " + pxVal + " ," + this.getClass().getSimpleName());
54 | }
55 | int val;
56 | if (useDefault())
57 | {
58 | val = defaultBaseWidth() ? getPercentWidthSize() : getPercentHeightSize();
59 | if (log)
60 | {
61 | L.e(" useDefault val= " + val);
62 | }
63 | } else if (baseWidth())
64 | {
65 | val = getPercentWidthSize();
66 | if (log)
67 | {
68 | L.e(" baseWidth val= " + val);
69 | }
70 | } else
71 | {
72 | val = getPercentHeightSize();
73 | if (log)
74 | {
75 | L.e(" baseHeight val= " + val);
76 | }
77 | }
78 |
79 | if (val > 0)
80 | val = Math.max(val, 1);//for very thin divider
81 | execute(view, val);
82 | }
83 |
84 | protected int getPercentWidthSize()
85 | {
86 | return AutoUtils.getPercentWidthSizeBigger(pxVal);
87 | }
88 |
89 | protected int getPercentHeightSize()
90 | {
91 | return AutoUtils.getPercentHeightSizeBigger(pxVal);
92 | }
93 |
94 |
95 | protected boolean baseWidth()
96 | {
97 | return contains(baseWidth, attrVal());
98 | }
99 |
100 | protected boolean useDefault()
101 | {
102 | return !contains(baseHeight, attrVal()) && !contains(baseWidth, attrVal());
103 | }
104 |
105 | protected boolean contains(int baseVal, int flag)
106 | {
107 | return (baseVal & flag) != 0;
108 | }
109 |
110 | protected abstract int attrVal();
111 |
112 | protected abstract boolean defaultBaseWidth();
113 |
114 | protected abstract void execute(View view, int val);
115 |
116 |
117 | @Override
118 | public String toString()
119 | {
120 | return "AutoAttr{" +
121 | "pxVal=" + pxVal +
122 | ", baseWidth=" + baseWidth() +
123 | ", defaultBaseWidth=" + defaultBaseWidth() +
124 | '}';
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/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 | public static HeightAttr generate(int val, int baseFlag)
36 | {
37 | HeightAttr heightAttr = null;
38 | switch (baseFlag)
39 | {
40 | case AutoAttr.BASE_WIDTH:
41 | heightAttr = new HeightAttr(val, Attrs.HEIGHT, 0);
42 | break;
43 | case AutoAttr.BASE_HEIGHT:
44 | heightAttr = new HeightAttr(val, 0, Attrs.HEIGHT);
45 | break;
46 | case AutoAttr.BASE_DEFAULT:
47 | heightAttr = new HeightAttr(val, 0, 0);
48 | break;
49 | }
50 | return heightAttr;
51 | }
52 |
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/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 | public static MarginBottomAttr generate(int val, int baseFlag)
40 | {
41 | MarginBottomAttr attr = null;
42 | switch (baseFlag)
43 | {
44 | case AutoAttr.BASE_WIDTH:
45 | attr = new MarginBottomAttr(val, Attrs.MARGIN_BOTTOM, 0);
46 | break;
47 | case AutoAttr.BASE_HEIGHT:
48 | attr = new MarginBottomAttr(val, 0, Attrs.MARGIN_BOTTOM);
49 | break;
50 | case AutoAttr.BASE_DEFAULT:
51 | attr = new MarginBottomAttr(val, 0, 0);
52 | break;
53 | }
54 | return attr;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/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 | public static MarginLeftAttr generate(int val, int baseFlag)
40 | {
41 | MarginLeftAttr attr = null;
42 | switch (baseFlag)
43 | {
44 | case AutoAttr.BASE_WIDTH:
45 | attr = new MarginLeftAttr(val, Attrs.MARGIN_LEFT, 0);
46 | break;
47 | case AutoAttr.BASE_HEIGHT:
48 | attr = new MarginLeftAttr(val, 0, Attrs.MARGIN_LEFT);
49 | break;
50 | case AutoAttr.BASE_DEFAULT:
51 | attr = new MarginLeftAttr(val, 0, 0);
52 | break;
53 | }
54 | return attr;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/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 |
40 | public static MarginRightAttr generate(int val, int baseFlag)
41 | {
42 | MarginRightAttr attr = null;
43 | switch (baseFlag)
44 | {
45 | case AutoAttr.BASE_WIDTH:
46 | attr = new MarginRightAttr(val, Attrs.MARGIN_RIGHT, 0);
47 | break;
48 | case AutoAttr.BASE_HEIGHT:
49 | attr = new MarginRightAttr(val, 0, Attrs.MARGIN_RIGHT);
50 | break;
51 | case AutoAttr.BASE_DEFAULT:
52 | attr = new MarginRightAttr(val, 0, 0);
53 | break;
54 | }
55 | return attr;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/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 |
40 |
41 | public static MarginTopAttr generate(int val, int baseFlag)
42 | {
43 | MarginTopAttr attr = null;
44 | switch (baseFlag)
45 | {
46 | case AutoAttr.BASE_WIDTH:
47 | attr = new MarginTopAttr(val, Attrs.MARGIN_TOP, 0);
48 | break;
49 | case AutoAttr.BASE_HEIGHT:
50 | attr = new MarginTopAttr(val, 0, Attrs.MARGIN_TOP);
51 | break;
52 | case AutoAttr.BASE_DEFAULT:
53 | attr = new MarginTopAttr(val, 0, 0);
54 | break;
55 | }
56 | return attr;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/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 | public static MaxHeightAttr generate(int val, int baseFlag)
42 | {
43 | MaxHeightAttr attr = null;
44 | switch (baseFlag)
45 | {
46 | case AutoAttr.BASE_WIDTH:
47 | attr = new MaxHeightAttr(val, Attrs.MAX_HEIGHT, 0);
48 | break;
49 | case AutoAttr.BASE_HEIGHT:
50 | attr = new MaxHeightAttr(val, 0, Attrs.MAX_HEIGHT);
51 | break;
52 | case AutoAttr.BASE_DEFAULT:
53 | attr = new MaxHeightAttr(val, 0, 0);
54 | break;
55 | }
56 | return attr;
57 | }
58 |
59 | public static int getMaxHeight(View view)
60 | {
61 | try
62 | {
63 | Method setMaxWidthMethod = view.getClass().getMethod("getMaxHeight");
64 | return (int) setMaxWidthMethod.invoke(view);
65 | } catch (Exception ignore)
66 | {
67 | }
68 | return 0;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/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 | public static MaxWidthAttr generate(int val, int baseFlag)
42 | {
43 | MaxWidthAttr attr = null;
44 | switch (baseFlag)
45 | {
46 | case AutoAttr.BASE_WIDTH:
47 | attr = new MaxWidthAttr(val, Attrs.MAX_WIDTH, 0);
48 | break;
49 | case AutoAttr.BASE_HEIGHT:
50 | attr = new MaxWidthAttr(val, 0, Attrs.MAX_WIDTH);
51 | break;
52 | case AutoAttr.BASE_DEFAULT:
53 | attr = new MaxWidthAttr(val, 0, 0);
54 | break;
55 | }
56 | return attr;
57 | }
58 |
59 | public static int getMaxWidth(View view)
60 | {
61 | try
62 | {
63 | Method setMaxWidthMethod = view.getClass().getMethod("getMaxWidth");
64 | return (int) setMaxWidthMethod.invoke(view);
65 | } catch (Exception ignore)
66 | {
67 | }
68 | return 0;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/autolayout/src/main/java/com/zhy/autolayout/attr/MinHeightAttr.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.attr;
2 |
3 | import android.os.Build;
4 | import android.view.View;
5 |
6 | import java.lang.reflect.Field;
7 |
8 | /**
9 | * Created by zhy on 15/12/24.
10 | */
11 | public class MinHeightAttr extends AutoAttr
12 | {
13 | public MinHeightAttr(int pxVal, int baseWidth, int baseHeight)
14 | {
15 | super(pxVal, baseWidth, baseHeight);
16 | }
17 |
18 | @Override
19 | protected int attrVal()
20 | {
21 | return Attrs.MIN_HEIGHT;
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 | try
34 | {
35 | view.setMinimumHeight(val);
36 | // Method setMaxWidthMethod = view.getClass().getMethod("setMinHeight", int.class);
37 | // setMaxWidthMethod.invoke(view, val);
38 | } catch (Exception ignore)
39 | {
40 | }
41 | }
42 |
43 | public static MinHeightAttr generate(int val, int baseFlag)
44 | {
45 | MinHeightAttr attr = null;
46 | switch (baseFlag)
47 | {
48 | case AutoAttr.BASE_WIDTH:
49 | attr = new MinHeightAttr(val, Attrs.MIN_HEIGHT, 0);
50 | break;
51 | case AutoAttr.BASE_HEIGHT:
52 | attr = new MinHeightAttr(val, 0, Attrs.MIN_HEIGHT);
53 | break;
54 | case AutoAttr.BASE_DEFAULT:
55 | attr = new MinHeightAttr(val, 0, 0);
56 | break;
57 | }
58 | return attr;
59 | }
60 |
61 | public static int getMinHeight(View view)
62 | {
63 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
64 | {
65 | return view.getMinimumHeight();
66 | } else
67 | {
68 | try
69 | {
70 | Field minHeight = view.getClass().getField("mMinHeight");
71 | minHeight.setAccessible(true);
72 | return (int) minHeight.get(view);
73 | } catch (Exception e)
74 | {
75 | }
76 | }
77 |
78 | return 0;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/autolayout/src/main/java/com/zhy/autolayout/attr/MinWidthAttr.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.attr;
2 |
3 | import android.os.Build;
4 | import android.view.View;
5 |
6 | import java.lang.reflect.Field;
7 |
8 | /**
9 | * Created by zhy on 15/12/24.
10 | */
11 | public class MinWidthAttr extends AutoAttr
12 | {
13 | public MinWidthAttr(int pxVal, int baseWidth, int baseHeight)
14 | {
15 | super(pxVal, baseWidth, baseHeight);
16 | }
17 |
18 | @Override
19 | protected int attrVal()
20 | {
21 | return Attrs.MIN_WIDTH;
22 | }
23 |
24 | @Override
25 | protected boolean defaultBaseWidth()
26 | {
27 | return true;
28 | }
29 |
30 | @Override
31 | protected void execute(View view, int val)
32 | {
33 | try
34 | {
35 | // Method setMaxWidthMethod = view.getClass().getMethod("setMinWidth", int.class);
36 | // setMaxWidthMethod.invoke(view, val);
37 | } catch (Exception ignore)
38 | {
39 | }
40 |
41 | view.setMinimumWidth(val);
42 | }
43 |
44 | public static int getMinWidth(View view)
45 | {
46 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
47 | return view.getMinimumWidth();
48 | try
49 | {
50 | Field minWidth = view.getClass().getField("mMinWidth");
51 | minWidth.setAccessible(true);
52 | return (int) minWidth.get(view);
53 | } catch (Exception ignore)
54 | {
55 | }
56 | return 0;
57 | }
58 |
59 |
60 | public static MinWidthAttr generate(int val, int baseFlag)
61 | {
62 | MinWidthAttr attr = null;
63 | switch (baseFlag)
64 | {
65 | case AutoAttr.BASE_WIDTH:
66 | attr = new MinWidthAttr(val, Attrs.MIN_WIDTH, 0);
67 | break;
68 | case AutoAttr.BASE_HEIGHT:
69 | attr = new MinWidthAttr(val, 0, Attrs.MIN_WIDTH);
70 | break;
71 | case AutoAttr.BASE_DEFAULT:
72 | attr = new MinWidthAttr(val, 0, 0);
73 | break;
74 | }
75 | return attr;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/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 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/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 |
39 | public static PaddingBottomAttr generate(int val, int baseFlag)
40 | {
41 | PaddingBottomAttr attr = null;
42 | switch (baseFlag)
43 | {
44 | case AutoAttr.BASE_WIDTH:
45 | attr = new PaddingBottomAttr(val, Attrs.PADDING_BOTTOM, 0);
46 | break;
47 | case AutoAttr.BASE_HEIGHT:
48 | attr = new PaddingBottomAttr(val, 0, Attrs.PADDING_BOTTOM);
49 | break;
50 | case AutoAttr.BASE_DEFAULT:
51 | attr = new PaddingBottomAttr(val, 0, 0);
52 | break;
53 | }
54 | return attr;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/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 |
39 | public static PaddingLeftAttr generate(int val, int baseFlag)
40 | {
41 | PaddingLeftAttr attr = null;
42 | switch (baseFlag)
43 | {
44 | case AutoAttr.BASE_WIDTH:
45 | attr = new PaddingLeftAttr(val, Attrs.PADDING_LEFT, 0);
46 | break;
47 | case AutoAttr.BASE_HEIGHT:
48 | attr = new PaddingLeftAttr(val, 0, Attrs.PADDING_LEFT);
49 | break;
50 | case AutoAttr.BASE_DEFAULT:
51 | attr = new PaddingLeftAttr(val, 0, 0);
52 | break;
53 | }
54 | return attr;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/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 |
39 | public static PaddingRightAttr generate(int val, int baseFlag)
40 | {
41 | PaddingRightAttr attr = null;
42 | switch (baseFlag)
43 | {
44 | case AutoAttr.BASE_WIDTH:
45 | attr = new PaddingRightAttr(val, Attrs.PADDING_RIGHT, 0);
46 | break;
47 | case AutoAttr.BASE_HEIGHT:
48 | attr = new PaddingRightAttr(val, 0, Attrs.PADDING_RIGHT);
49 | break;
50 | case AutoAttr.BASE_DEFAULT:
51 | attr = new PaddingRightAttr(val, 0, 0);
52 | break;
53 | }
54 | return attr;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/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 | public static PaddingTopAttr generate(int val, int baseFlag)
38 | {
39 | PaddingTopAttr attr = null;
40 | switch (baseFlag)
41 | {
42 | case AutoAttr.BASE_WIDTH:
43 | attr = new PaddingTopAttr(val, Attrs.PADDING_TOP, 0);
44 | break;
45 | case AutoAttr.BASE_HEIGHT:
46 | attr = new PaddingTopAttr(val, 0, Attrs.PADDING_TOP);
47 | break;
48 | case AutoAttr.BASE_DEFAULT:
49 | attr = new PaddingTopAttr(val, 0, 0);
50 | break;
51 | }
52 | return attr;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/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 | public static TextSizeAttr generate(int val, int baseFlag)
40 | {
41 | TextSizeAttr attr = null;
42 | switch (baseFlag)
43 | {
44 | case AutoAttr.BASE_WIDTH:
45 | attr = new TextSizeAttr(val, Attrs.TEXTSIZE, 0);
46 | break;
47 | case AutoAttr.BASE_HEIGHT:
48 | attr = new TextSizeAttr(val, 0, Attrs.TEXTSIZE);
49 | break;
50 | case AutoAttr.BASE_DEFAULT:
51 | attr = new TextSizeAttr(val, 0, 0);
52 | break;
53 | }
54 | return attr;
55 | }
56 |
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/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 | public static WidthAttr generate(int val, int baseFlag)
36 | {
37 | WidthAttr widthAttr = null;
38 | switch (baseFlag)
39 | {
40 | case AutoAttr.BASE_WIDTH:
41 | widthAttr = new WidthAttr(val, Attrs.WIDTH, 0);
42 | break;
43 | case AutoAttr.BASE_HEIGHT:
44 | widthAttr = new WidthAttr(val, 0, Attrs.WIDTH);
45 | break;
46 | case AutoAttr.BASE_DEFAULT:
47 | widthAttr = new WidthAttr(val, 0, 0);
48 | break;
49 | }
50 | return widthAttr;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/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/AutoUtils.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.utils;
2 |
3 | import android.view.View;
4 |
5 | import com.zhy.autolayout.AutoLayoutInfo;
6 | import com.zhy.autolayout.R;
7 | import com.zhy.autolayout.attr.Attrs;
8 | import com.zhy.autolayout.attr.AutoAttr;
9 | import com.zhy.autolayout.config.AutoLayoutConifg;
10 |
11 | /**
12 | * Created by zhy on 15/12/4.
13 | */
14 | public class AutoUtils
15 | {
16 |
17 | /**
18 | * 会直接将view的LayoutParams上设置的width,height直接进行百分比处理
19 | *
20 | * @param view
21 | */
22 | public static void auto(View view)
23 | {
24 | autoSize(view);
25 | autoPadding(view);
26 | autoMargin(view);
27 | autoTextSize(view, AutoAttr.BASE_DEFAULT);
28 | }
29 |
30 | /**
31 | * @param view
32 | * @param attrs #Attrs.WIDTH|Attrs.HEIGHT
33 | * @param base AutoAttr.BASE_WIDTH|AutoAttr.BASE_HEIGHT|AutoAttr.BASE_DEFAULT
34 | */
35 | public static void auto(View view, int attrs, int base)
36 | {
37 | AutoLayoutInfo autoLayoutInfo = AutoLayoutInfo.getAttrFromView(view, attrs, base);
38 | if (autoLayoutInfo != null)
39 | autoLayoutInfo.fillAttrs(view);
40 | }
41 |
42 | public static void autoTextSize(View view)
43 | {
44 | auto(view, Attrs.TEXTSIZE, AutoAttr.BASE_DEFAULT);
45 | }
46 |
47 | public static void autoTextSize(View view, int base)
48 | {
49 | auto(view, Attrs.TEXTSIZE, base);
50 | }
51 |
52 | public static void autoMargin(View view)
53 | {
54 | auto(view, Attrs.MARGIN, AutoAttr.BASE_DEFAULT);
55 | }
56 |
57 | public static void autoMargin(View view, int base)
58 | {
59 | auto(view, Attrs.MARGIN, base);
60 | }
61 |
62 | public static void autoPadding(View view)
63 | {
64 | auto(view, Attrs.PADDING, AutoAttr.BASE_DEFAULT);
65 | }
66 |
67 | public static void autoPadding(View view, int base)
68 | {
69 | auto(view, Attrs.PADDING, base);
70 | }
71 |
72 | public static void autoSize(View view)
73 | {
74 | auto(view, Attrs.WIDTH | Attrs.HEIGHT, AutoAttr.BASE_DEFAULT);
75 | }
76 |
77 | public static void autoSize(View view, int base)
78 | {
79 | auto(view, Attrs.WIDTH | Attrs.HEIGHT, base);
80 | }
81 |
82 | public static boolean autoed(View view)
83 | {
84 | Object tag = view.getTag(R.id.id_tag_autolayout_size);
85 | if (tag != null) return true;
86 | view.setTag(R.id.id_tag_autolayout_size, "Just Identify");
87 | return false;
88 | }
89 |
90 | public static float getPercentWidth1px()
91 | {
92 | int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth();
93 | int designWidth = AutoLayoutConifg.getInstance().getDesignWidth();
94 | return 1.0f * screenWidth / designWidth;
95 | }
96 |
97 | public static float getPercentHeight1px()
98 | {
99 | int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight();
100 | int designHeight = AutoLayoutConifg.getInstance().getDesignHeight();
101 | return 1.0f * screenHeight / designHeight;
102 | }
103 |
104 |
105 | public static int getPercentWidthSize(int val)
106 | {
107 | int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth();
108 | int designWidth = AutoLayoutConifg.getInstance().getDesignWidth();
109 | return (int) (val * 1.0f / designWidth * screenWidth);
110 | }
111 |
112 |
113 | public static int getPercentWidthSizeBigger(int val)
114 | {
115 | int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth();
116 | int designWidth = AutoLayoutConifg.getInstance().getDesignWidth();
117 |
118 | int res = val * screenWidth;
119 | if (res % designWidth == 0)
120 | {
121 | return res / designWidth;
122 | } else
123 | {
124 | return res / designWidth + 1;
125 | }
126 |
127 | }
128 |
129 | public static int getPercentHeightSizeBigger(int val)
130 | {
131 | int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight();
132 | int designHeight = AutoLayoutConifg.getInstance().getDesignHeight();
133 |
134 | int res = val * screenHeight;
135 | if (res % designHeight == 0)
136 | {
137 | return res / designHeight;
138 | } else
139 | {
140 | return res / designHeight + 1;
141 | }
142 | }
143 |
144 | public static int getPercentHeightSize(int val)
145 | {
146 | int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight();
147 | int designHeight = AutoLayoutConifg.getInstance().getDesignHeight();
148 |
149 | return (int) (val * 1.0f / designHeight * screenHeight);
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/autolayout/src/main/java/com/zhy/autolayout/utils/DimenUtils.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.utils;
2 |
3 | import android.util.TypedValue;
4 |
5 | /**
6 | * Created by zhy on 16/3/3.
7 | */
8 | public class DimenUtils
9 | {
10 | private static int getComplexUnit(int data)
11 | {
12 | return TypedValue.COMPLEX_UNIT_MASK & (data >> TypedValue.COMPLEX_UNIT_SHIFT);
13 | }
14 |
15 | public static boolean isPxVal(TypedValue val)
16 | {
17 | if (val != null && val.type == TypedValue.TYPE_DIMENSION &&
18 | getComplexUnit(val.data) == TypedValue.COMPLEX_UNIT_PX)
19 | {
20 | return true;
21 | }
22 | return false;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/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.content.res.Resources;
5 | import android.graphics.Point;
6 | import android.os.Build;
7 | import android.util.DisplayMetrics;
8 | import android.view.Display;
9 | import android.view.WindowManager;
10 |
11 | /**
12 | * Created by zhy on 15/12/4.
13 | * form http://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels/15699681#15699681
14 | */
15 | public class ScreenUtils
16 | {
17 |
18 | public static int getStatusBarHeight(Context context)
19 | {
20 | int result = 0;
21 | try
22 | {
23 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
24 | if (resourceId > 0)
25 | {
26 | result = context.getResources().getDimensionPixelSize(resourceId);
27 | }
28 | } catch (Resources.NotFoundException e)
29 | {
30 | e.printStackTrace();
31 | }
32 | return result;
33 | }
34 |
35 |
36 | public static int[] getScreenSize(Context context, boolean useDeviceSize)
37 | {
38 |
39 | int[] size = new int[2];
40 |
41 | WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
42 | Display d = w.getDefaultDisplay();
43 | DisplayMetrics metrics = new DisplayMetrics();
44 | d.getMetrics(metrics);
45 | // since SDK_INT = 1;
46 | int widthPixels = metrics.widthPixels;
47 | int heightPixels = metrics.heightPixels;
48 |
49 | if (!useDeviceSize)
50 | {
51 | size[0] = widthPixels;
52 | size[1] = heightPixels - getStatusBarHeight(context);
53 |
54 | return size;
55 | }
56 |
57 | // includes window decorations (statusbar bar/menu bar)
58 | if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17)
59 | try
60 | {
61 | widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
62 | heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
63 | } catch (Exception ignored)
64 | {
65 | }
66 | // includes window decorations (statusbar bar/menu bar)
67 | if (Build.VERSION.SDK_INT >= 17)
68 | try
69 | {
70 | Point realSize = new Point();
71 | Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize);
72 | widthPixels = realSize.x;
73 | heightPixels = realSize.y;
74 | } catch (Exception ignored)
75 | {
76 | }
77 | size[0] = widthPixels;
78 | size[1] = heightPixels;
79 | return size;
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/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/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/autolayout_01.png
--------------------------------------------------------------------------------
/autolayout_02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/autolayout_02.png
--------------------------------------------------------------------------------
/autolayout_03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/autolayout_03.png
--------------------------------------------------------------------------------
/autolayout_04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/autolayout_04.png
--------------------------------------------------------------------------------
/autolayout_06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/autolayout_06.png
--------------------------------------------------------------------------------
/autolayout_07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/autolayout_07.png
--------------------------------------------------------------------------------
/autolayout_08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/autolayout_08.png
--------------------------------------------------------------------------------
/autolayout_09.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/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-plugin:1.2'
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | jcenter()
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/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/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/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/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/preview/preview_01.png
--------------------------------------------------------------------------------
/preview/preview_02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/preview/preview_02.png
--------------------------------------------------------------------------------
/preview/preview_03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/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.zhy:base-adapter:2.0.2'
27 | compile 'com.android.support:design:23.1.0'
28 | compile 'com.android.support:cardview-v7:23.1.0'
29 | compile 'com.android.support:recyclerview-v7:23.2.0'
30 | }
31 |
--------------------------------------------------------------------------------
/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.content.Context;
4 | import android.os.Bundle;
5 | import android.support.design.widget.TabLayout;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentPagerAdapter;
8 | import android.support.v4.view.ViewPager;
9 |
10 | import com.zhy.autolayout.AutoLayoutActivity;
11 | import com.zhy.sample.fragment.SimpleFragment;
12 |
13 | public class CategoryActivity extends AutoLayoutActivity
14 | {
15 |
16 | private TabLayout mTabLayout;
17 | private ViewPager mViewPager;
18 |
19 | private String[] mTabTitles = new String[]
20 | {"单个UI", "正方形"};
21 |
22 |
23 | @Override
24 | public Context getBaseContext()
25 | {
26 | return super.getBaseContext();
27 | }
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState)
31 | {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_category);
34 |
35 |
36 | mTabLayout = (TabLayout) findViewById(R.id.id_tablayout);
37 | mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
38 |
39 | mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager())
40 | {
41 | @Override
42 | public Fragment getItem(int i)
43 | {
44 | return new SimpleFragment();
45 | }
46 |
47 | @Override
48 | public CharSequence getPageTitle(int position)
49 | {
50 |
51 | return mTabTitles[position];
52 | }
53 |
54 | @Override
55 | public int getCount()
56 | {
57 | return mTabTitles.length;
58 | }
59 | });
60 |
61 |
62 | mTabLayout.setupWithViewPager(mViewPager);
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/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.RecyclerViewFragment;
17 | import com.zhy.sample.fragment.RecyclerViewGridFragment;
18 | import com.zhy.sample.fragment.RegisterFragment;
19 | import com.zhy.sample.fragment.TestFragment;
20 |
21 | import java.util.ArrayList;
22 |
23 | public class MainActivity extends AutoLayoutActivity
24 | {
25 |
26 | private ViewPager mViewPager;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | //requestWindowFeature(Window.FEATURE_NO_TITLE);
32 | setImmersionStatus();
33 | setContentView(R.layout.activity_main);
34 |
35 |
36 | initView();
37 | initDatas();
38 | }
39 |
40 | private void setImmersionStatus() {
41 | if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
42 | // 透明状态栏
43 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
44 | // 透明导航栏
45 | // getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
46 | }
47 | }
48 |
49 | private void initDatas() {
50 | ArrayList mList = new ArrayList();
51 | mList.add(new ListFragment());
52 | mList.add(new RegisterFragment());
53 | mList.add(new PayFragment());
54 | mList.add(new RecyclerViewFragment());
55 | mList.add(new RecyclerViewGridFragment());
56 | mList.add(new TestFragment());
57 | mViewPager.setAdapter(new MyAdapter(getSupportFragmentManager(), mList));
58 | }
59 |
60 | private void initView() {
61 | mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
62 | }
63 |
64 | @Override
65 | public boolean onCreateOptionsMenu(Menu menu)
66 | {
67 | // Inflate the menu; this adds items to the action bar if it is present.
68 | getMenuInflater().inflate(R.menu.menu_main, menu);
69 | return true;
70 | }
71 |
72 |
73 | public class MyAdapter extends FragmentPagerAdapter {
74 | ArrayList tabs = null;
75 |
76 | public MyAdapter(FragmentManager fm, ArrayList tabs) {
77 | super(fm);
78 | this.tabs = tabs;
79 | }
80 |
81 | @Override
82 | public Fragment getItem(int pos) {
83 | return tabs.get(pos);
84 | }
85 |
86 | @Override
87 | public int getCount() {
88 | return tabs.size();
89 | }
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/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 | // mlistview.setAdapter(new CommonAdapter(getActivity(),R.layout.list_item,mList)
46 | // {
47 | // @Override
48 | // protected void onConvertViewCreated(View convertView)
49 | // {
50 | // AutoUtils.autoSize(convertView);
51 | // }
52 | //
53 | // @Override
54 | // public void convert(com.zhy.base.adapter.ViewHolder viewHolder, String s)
55 | // {
56 | //
57 | // }
58 | // });
59 | }
60 |
61 | class MyAdapter extends BaseAdapter
62 | {
63 |
64 | @Override
65 | public int getCount()
66 | {
67 | return mList.size();
68 | }
69 |
70 | @Override
71 | public Object getItem(int arg0)
72 | {
73 | return mList.get(arg0);
74 | }
75 |
76 | @Override
77 | public long getItemId(int position)
78 | {
79 | return position;
80 | }
81 |
82 | @Override
83 | public View getView(int position, View convertView, ViewGroup parent)
84 | {
85 | ViewHolder holder = null;
86 | if (convertView == null)
87 | {
88 | holder = new ViewHolder();
89 | convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false);
90 | convertView.setTag(holder);
91 | //对于listview,注意添加这一行,即可在item上使用高度
92 | AutoUtils.autoSize(convertView);
93 | } else
94 | {
95 | holder = (ViewHolder) convertView.getTag();
96 | }
97 |
98 | return convertView;
99 | }
100 |
101 | }
102 |
103 | class ViewHolder
104 | {
105 |
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/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/RecyclerViewFragment.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.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.zhy.autolayout.utils.AutoUtils;
14 | import com.zhy.base.adapter.recyclerview.CommonAdapter;
15 | import com.zhy.sample.R;
16 | import com.zhy.sample.view.DividerItemDecoration;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | public class RecyclerViewFragment extends Fragment
22 | {
23 | private View mView;
24 | private RecyclerView mRecyclerView;
25 | private List mList;
26 | private Context mContext;
27 |
28 | @Override
29 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
30 | {
31 | mView = inflater.inflate(R.layout.fragment_recyclerview, container, false);
32 | initView();
33 | return mView;
34 | }
35 |
36 | private void initView()
37 | {
38 | mContext = getActivity();
39 | mRecyclerView = (RecyclerView) mView.findViewById(R.id.id_recyclerview);
40 | mList = new ArrayList();
41 | for (int i = 0; i < 50; i++)
42 | {
43 | mList.add(i + "");
44 | }
45 | mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
46 | mRecyclerView.setAdapter(new MyAdapter(getActivity(),mList));
47 |
48 | mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(),
49 | DividerItemDecoration.VERTICAL_LIST));
50 | }
51 |
52 | class MyAdapter extends CommonAdapter
53 | {
54 | public MyAdapter(Context context, List datas)
55 | {
56 | super(context, R.layout.recyclerview_item, datas);
57 | }
58 |
59 | @Override
60 | public com.zhy.base.adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
61 | {
62 | com.zhy.base.adapter.ViewHolder viewHolder = super.onCreateViewHolder(parent, viewType);
63 | AutoUtils.autoSize(viewHolder.getConvertView());
64 | return viewHolder;
65 | }
66 |
67 | @Override
68 | public void convert(com.zhy.base.adapter.ViewHolder viewHolder, String s)
69 | {
70 | }
71 | }
72 |
73 |
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/zhy/sample/fragment/RecyclerViewGridFragment.java:
--------------------------------------------------------------------------------
1 | package com.zhy.sample.fragment;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v7.widget.GridLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 |
14 | import com.zhy.autolayout.attr.AutoAttr;
15 | import com.zhy.autolayout.utils.AutoUtils;
16 | import com.zhy.sample.R;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 | import java.util.Random;
21 |
22 | public class RecyclerViewGridFragment extends Fragment
23 | {
24 | private View mView;
25 | private RecyclerView mRecyclerView;
26 | private List mList;
27 | private Context mContext;
28 |
29 | @Override
30 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
31 | {
32 | mView = inflater.inflate(R.layout.fragment_recyclerview_grid, container, false);
33 | initView();
34 | return mView;
35 | }
36 |
37 | private void initView()
38 | {
39 | mContext = getActivity();
40 | mRecyclerView = (RecyclerView) mView.findViewById(R.id.id_recyclerview);
41 | mList = new ArrayList();
42 | for (int i = 0; i < 50; i++)
43 | {
44 | mList.add(i + "");
45 | }
46 | mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2, GridLayoutManager.HORIZONTAL, false));
47 | mRecyclerView.setAdapter(new MyAdapter());
48 |
49 | }
50 |
51 | class MyAdapter extends RecyclerView.Adapter
52 | {
53 | @Override
54 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
55 | {
56 | View convertView = LayoutInflater.from(mContext).inflate(R.layout.recyclerview_item_grid, parent, false);
57 | return new ViewHolder(convertView);
58 | }
59 |
60 | @Override
61 | public void onBindViewHolder(ViewHolder holder, int position)
62 | {
63 |
64 | }
65 |
66 | @Override
67 | public long getItemId(int position)
68 | {
69 | return position;
70 | }
71 |
72 | @Override
73 | public int getItemCount()
74 | {
75 | return mList.size();
76 | }
77 |
78 |
79 | }
80 |
81 | static class ViewHolder extends RecyclerView.ViewHolder
82 | {
83 |
84 | public ViewHolder(View itemView)
85 | {
86 | super(itemView);
87 | Random random = new Random();
88 | itemView.setBackgroundColor(Color.argb(200, random.nextInt(255), random.nextInt(255), random.nextInt(255)));
89 | //recyclerview,注意添加这一行
90 | AutoUtils.autoSize(itemView, AutoAttr.BASE_HEIGHT);
91 | // Log.e("", itemView.getLayoutParams().width + " , " + itemView.getLayoutParams().height);
92 | }
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/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/fragment/TestFragment.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 TestFragment 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.activity_test, container, false);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/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/java/com/zhy/sample/view/DividerItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.zhy.sample.view;/*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * limitations under the License.
6 | */
7 |
8 | import android.content.Context;
9 | import android.content.res.TypedArray;
10 | import android.graphics.Canvas;
11 | import android.graphics.Rect;
12 | import android.graphics.drawable.Drawable;
13 | import android.support.v7.widget.LinearLayoutManager;
14 | import android.support.v7.widget.RecyclerView;
15 | import android.util.Log;
16 | import android.view.View;
17 |
18 |
19 | /**
20 | * This class is from the v7 samples of the Android SDK. It's not by me!
21 | *
22 | * See the license above for details.
23 | */
24 | public class DividerItemDecoration extends RecyclerView.ItemDecoration {
25 |
26 | private static final int[] ATTRS = new int[]{
27 | android.R.attr.listDivider
28 | };
29 |
30 | public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
31 |
32 | public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
33 |
34 | private Drawable mDivider;
35 |
36 | private int mOrientation;
37 |
38 | public DividerItemDecoration(Context context, int orientation) {
39 | final TypedArray a = context.obtainStyledAttributes(ATTRS);
40 | mDivider = a.getDrawable(0);
41 | a.recycle();
42 | setOrientation(orientation);
43 | }
44 |
45 | public void setOrientation(int orientation) {
46 | if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
47 | throw new IllegalArgumentException("invalid orientation");
48 | }
49 | mOrientation = orientation;
50 | }
51 |
52 | @Override
53 | public void onDraw(Canvas c, RecyclerView parent) {
54 | Log.v("recyclerview - itemdecoration", "onDraw()");
55 |
56 | if (mOrientation == VERTICAL_LIST) {
57 | drawVertical(c, parent);
58 | } else {
59 | drawHorizontal(c, parent);
60 | }
61 |
62 | }
63 |
64 |
65 | public void drawVertical(Canvas c, RecyclerView parent) {
66 | final int left = parent.getPaddingLeft();
67 | final int right = parent.getWidth() - parent.getPaddingRight();
68 |
69 | final int childCount = parent.getChildCount();
70 | for (int i = 0; i < childCount; i++) {
71 | final View child = parent.getChildAt(i);
72 | RecyclerView v = new RecyclerView(parent.getContext());
73 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
74 | .getLayoutParams();
75 | final int top = child.getBottom() + params.bottomMargin;
76 | final int bottom = top + mDivider.getIntrinsicHeight();
77 | mDivider.setBounds(left, top, right, bottom);
78 | mDivider.draw(c);
79 | }
80 | }
81 |
82 | public void drawHorizontal(Canvas c, RecyclerView parent) {
83 | final int top = parent.getPaddingTop();
84 | final int bottom = parent.getHeight() - parent.getPaddingBottom();
85 |
86 | final int childCount = parent.getChildCount();
87 | for (int i = 0; i < childCount; i++) {
88 | final View child = parent.getChildAt(i);
89 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
90 | .getLayoutParams();
91 | final int left = child.getRight() + params.rightMargin;
92 | final int right = left + mDivider.getIntrinsicHeight();
93 | mDivider.setBounds(left, top, right, bottom);
94 | mDivider.draw(c);
95 | }
96 | }
97 |
98 | @Override
99 | public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
100 | if (mOrientation == VERTICAL_LIST) {
101 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
102 | } else {
103 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
104 | }
105 | }
106 | }
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/daili_xuanzhong.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/daili_xuanzhong.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/daili_yuanquan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/daili_yuanquan.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/login_dengluhao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/login_dengluhao.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/login_fanhui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/login_fanhui.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/login_miam.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/login_miam.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/login_yanzhengma.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/login_yanzhengma.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/login_zaicishurumima.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/login_zaicishurumima.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/wode_weixinzhifu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/wode_weixinzhifu.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/wode_zhifubaozhifu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/wode_zhifubaozhifu.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/wode_zijin_dise.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-hdpi/wode_zijin_dise.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/login_dengluhao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xhdpi/login_dengluhao.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/login_miam.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xhdpi/login_miam.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/login_yanzhengma.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xhdpi/login_yanzhengma.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/login_zaicishurumima.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xhdpi/login_zaicishurumima.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/tuijian_dailishangpaihangbang.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xhdpi/tuijian_dailishangpaihangbang.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/tuijian_pinpaituijian.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xhdpi/tuijian_pinpaituijian.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/tuijian_rexiaopin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xhdpi/tuijian_rexiaopin.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/tuijian_touxiang6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xhdpi/tuijian_touxiang6.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/tuijian_xinpintuijia.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xhdpi/tuijian_xinpintuijia.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/login_dengluhao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xxhdpi/login_dengluhao.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/login_fanhui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xxhdpi/login_fanhui.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/login_miam.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xxhdpi/login_miam.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/login_yanzhengma.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/drawable-xxhdpi/login_yanzhengma.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/login_zaicishurumima.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/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/activity_test.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
16 |
17 |
18 |
19 |
30 |
--------------------------------------------------------------------------------
/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_recyclerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/fragment_recyclerview_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/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/layout/recyclerview_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
17 |
18 |
26 |
27 |
36 |
37 |
46 |
47 |
56 |
57 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/recyclerview_item_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
21 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_test.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/mipmap-hdpi/add.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/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', ':autolayout-widget'
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 project(':autolayout')
25 | compile project(':autolayout-widget')
26 | compile 'com.android.support:design:23.1.1'
27 | compile 'com.android.support:support-v4:23.1.1'
28 | compile 'com.android.support:appcompat-v7:23.1.1'
29 | compile 'com.android.support:gridlayout-v7:23.1.1'
30 | compile 'com.android.support:cardview-v7:23.1.1'
31 | }
32 |
--------------------------------------------------------------------------------
/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.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 | import android.support.v7.widget.Toolbar;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 |
12 | import com.zhy.autolayout.test.widgets.fragments.SimpleFragment;
13 | import com.zhy.autolayout.widget.AutoLayoutWidgetActivity;
14 |
15 | public class MainActivity extends AutoLayoutWidgetActivity {
16 | private TabLayout mTabLayout;
17 | private ViewPager mViewPager;
18 |
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 |
25 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
26 | toolbar.setTitle("标题");
27 | setSupportActionBar(toolbar);
28 | mTabLayout = (TabLayout) findViewById(R.id.id_tablayout);
29 | mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
30 |
31 | mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
32 | @Override
33 | public Fragment getItem(int position) {
34 | return new SimpleFragment();
35 | }
36 |
37 | @Override
38 | public int getCount() {
39 | return 2;
40 | }
41 |
42 | @Override
43 | public CharSequence getPageTitle(int position) {
44 | return "Page " + position;
45 | }
46 | });
47 |
48 | mTabLayout.setupWithViewPager(mViewPager);
49 |
50 | }
51 |
52 | @Override
53 | public boolean onCreateOptionsMenu(Menu menu) {
54 | // Inflate the menu; this adds items to the action bar if it is present.
55 | getMenuInflater().inflate(R.menu.menu_main, menu);
56 | return true;
57 | }
58 |
59 | @Override
60 | public boolean onOptionsItemSelected(MenuItem item) {
61 | // Handle action bar item clicks here. The action bar will
62 | // automatically handle clicks on the Home/Up button, so long
63 | // as you specify a parent activity in AndroidManifest.xml.
64 | int id = item.getItemId();
65 |
66 | //noinspection SimplifiableIfStatement
67 | if (id == R.id.action_settings) {
68 | return true;
69 | }
70 |
71 | return super.onOptionsItemSelected(item);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/widgetsample/src/main/java/com/zhy/autolayout/test/widgets/fragments/SimpleFragment.java:
--------------------------------------------------------------------------------
1 | package com.zhy.autolayout.test.widgets.fragments;
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.autolayout.test.widgets.R;
11 |
12 | /**
13 | * Created by zhy on 16/3/3.
14 | */
15 | public class SimpleFragment extends Fragment
16 | {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
20 | {
21 | return inflater.inflate(R.layout.fragment_simple, container, false);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/widgetsample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
19 |
20 |
21 |
22 |
31 |
32 |
33 |
38 |
39 |
--------------------------------------------------------------------------------
/widgetsample/src/main/res/layout/fragment_simple.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/widgetsample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/widgetsample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/widgetsample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/widgetsample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/widgetsample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/widgetsample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/widgetsample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/widgetsample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hongyangAndroid/AndroidAutoLayout/d0045f33d2a944bebbc07ab3d54a1c19b9d2963b/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 | 设置
6 |
7 |
--------------------------------------------------------------------------------
/widgetsample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
11 |
15 |
16 |
19 |
20 |
23 |
24 |
--------------------------------------------------------------------------------