Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加不用继承 AutoLayoutActivity 的方式适配 #91

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ dependencies {
* RelativeLayout -> AutoRelativeLayout
* FrameLayout -> AutoFrameLayout

或者在 Activity 中重写 onCreateView
```java
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
View view = AutoLayoutHelper.onCreateAutoLayoutView(name, context, attrs);
return view != null ? view : super.onCreateView(name, context, attrs);
}
```

这样也可以完成适配。

## 目前支持属性
Expand Down
17 changes: 10 additions & 7 deletions autolayout-widget/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}

}

dependencies {
Expand Down
105 changes: 22 additions & 83 deletions autolayout/build.gradle
Original file line number Diff line number Diff line change
@@ -1,100 +1,39 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "1.4.5"
apply plugin: 'maven'
apply plugin: 'com.novoda.bintray-release'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
minSdkVersion 7
targetSdkVersion 23
versionCode 1
versionName "1.0"
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

def siteUrl = 'https://github.com/hongyangAndroid/AndroidAutoLayout' // #CONFIG# // project homepage
def gitUrl = 'https://github.com/hongyangAndroid/AndroidAutoLayout.git' // #CONFIG# // project git
group = "com.zhy"

install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
name 'AutoLayout' // #CONFIG# // project title
url siteUrl
// Set your license
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'hongyangAndroid' // #CONFIG# // your user id (you can write your nickname)
name 'ZhangHongyang' // #CONFIG# // your user name
email '[email protected]' // #CONFIG# // your email
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
productFlavors {
}
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives javadocJar
archives sourcesJar
}
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = "maven"
name = "autolayout" // #CONFIG# project name in jcenter
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}


dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
provided rootProject.ext.dependencies.appcompatV7
}

publish {
userOrg = 'mylhyl'
groupId = 'com.mylhyl'
artifactId = 'autolayout'
version = rootProject.ext.publish.version
description = 'AndroidAutoLayout'
website = "https://github.com/mylhyl/AndroidAutoLayout"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,16 @@
import android.util.AttributeSet;
import android.view.View;

;
;import com.zhy.autolayout.utils.AutoLayoutHelper;

/**
* Created by zhy on 15/11/19.
*/
public class AutoLayoutActivity extends AppCompatActivity
{
private static final String LAYOUT_LINEARLAYOUT = "LinearLayout";
private static final String LAYOUT_FRAMELAYOUT = "FrameLayout";
private static final String LAYOUT_RELATIVELAYOUT = "RelativeLayout";

public class AutoLayoutActivity extends AppCompatActivity {

@Override
public View onCreateView(String name, Context context, AttributeSet attrs)
{
View view = null;
if (name.equals(LAYOUT_FRAMELAYOUT))
{
view = new AutoFrameLayout(context, attrs);
}

if (name.equals(LAYOUT_LINEARLAYOUT))
{
view = new AutoLinearLayout(context, attrs);
}

if (name.equals(LAYOUT_RELATIVELAYOUT))
{
view = new AutoRelativeLayout(context, attrs);
}

if (view != null) return view;

return super.onCreateView(name, context, attrs);
public View onCreateView(String name, Context context, AttributeSet attrs) {
View view = AutoLayoutHelper.onCreateAutoLayoutView(name, context, attrs);
return view != null ? view : super.onCreateView(name, context, attrs);
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Created by zhy on 15/12/5.
* <p/>
* <p>
* 与attrs.xml中数值对应
*/
public interface Attrs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import android.view.View;
import android.view.ViewGroup;

import com.zhy.autolayout.AutoFrameLayout;
import com.zhy.autolayout.AutoLayoutInfo;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;
import com.zhy.autolayout.R;
import com.zhy.autolayout.attr.HeightAttr;
import com.zhy.autolayout.attr.MarginAttr;
Expand Down Expand Up @@ -88,6 +91,9 @@ public class AutoLayoutHelper
private static final int INDEX_MIN_WIDTH = 15;
private static final int INDEX_MIN_HEIGHT = 16;

private static final String LAYOUT_LINEARLAYOUT = "LinearLayout";
private static final String LAYOUT_FRAMELAYOUT = "FrameLayout";
private static final String LAYOUT_RELATIVELAYOUT = "RelativeLayout";

/**
* move to other place?
Expand Down Expand Up @@ -230,4 +236,21 @@ public interface AutoLayoutParams
{
AutoLayoutInfo getAutoLayoutInfo();
}

public static View onCreateAutoLayoutView(String name, Context context, AttributeSet attrs) {
View view = null;
if (name.equals(LAYOUT_LINEARLAYOUT)) {
view = new AutoLinearLayout(context, attrs);
}

if (name.equals(LAYOUT_FRAMELAYOUT)) {
view = new AutoFrameLayout(context, attrs);
}

if (name.equals(LAYOUT_RELATIVELAYOUT)) {
view = new AutoRelativeLayout(context, attrs);
}

return view;
}
}
Loading