Skip to content

Commit

Permalink
修复有y轴偏移时高度问题,升级依赖库
Browse files Browse the repository at this point in the history
  • Loading branch information
Jankin6 committed Aug 27, 2020
1 parent d3b1e91 commit eeb05f7
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## 添加到项目

```groovy
implementation 'com.jankin.popupwindowcompat:lib:1.0.3'
implementation 'com.jankin.popupwindowcompat:lib:1.0.4'
```

## 使用
Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A compatible Popwindow adapt android 7.x , 8.x etc, Mainly adapts to the height
## Adding to your project

```groovy
implementation 'com.jankin.popupwindowcompat:lib:1.0.3'
implementation 'com.jankin.popupwindowcompat:lib:1.0.4'
```

## Simple Usage
Expand Down
15 changes: 8 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
compileSdkVersion 29
defaultConfig {
applicationId "com.jankin.study.popupwindowcompact"
minSdkVersion 15
targetSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '29.0.3'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:26.1.0"
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation project(':lib')
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jankin.study.popupwindowcompact;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.jankin.study.popupwindowcompat;

import android.graphics.drawable.BitmapDrawable;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -16,6 +17,7 @@ public class MainActivity extends AppCompatActivity {
Button btn_match;
Button btn_wrap;
Button btn_fix;
Button btn_at_location;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -24,6 +26,7 @@ protected void onCreate(Bundle savedInstanceState) {
btn_match = findViewById(R.id.btn_match);
btn_wrap = findViewById(R.id.btn_wrap);
btn_fix = findViewById(R.id.btn_fix);
btn_at_location = findViewById(R.id.btn_at_location);

btn_match.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -46,10 +49,17 @@ public void onClick(View view) {
showFixPopupwindow();
}
});
btn_at_location.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

showAtLocationPopupwindow();
}
});
}


private void showMatchPopupwindow(){
private void showMatchPopupwindow() {
PopupWindowCompat popupWindow = new PopupWindowCompat(this);
View contentView = LayoutInflater.from(this).inflate(R.layout.ppw_layout, null);
popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
Expand All @@ -58,10 +68,10 @@ private void showMatchPopupwindow(){
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAsDropDown(btn_match);
popupWindow.showAsDropDown(btn_match, 0, 200);
}

private void showWrapPopupwindow(){
private void showWrapPopupwindow() {
PopupWindowCompat popupWindow = new PopupWindowCompat(this);
View contentView = LayoutInflater.from(this).inflate(R.layout.ppw_layout, null);
popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
Expand All @@ -70,10 +80,10 @@ private void showWrapPopupwindow(){
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAsDropDown(btn_wrap);
popupWindow.showAsDropDown(btn_wrap, 0, 200);
}

private void showFixPopupwindow(){
private void showFixPopupwindow() {
PopupWindowCompat popupWindow = new PopupWindowCompat(this);
View contentView = LayoutInflater.from(this).inflate(R.layout.ppw_layout, null);
popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
Expand All @@ -82,6 +92,18 @@ private void showFixPopupwindow(){
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAsDropDown(btn_fix);
popupWindow.showAsDropDown(btn_fix, 0, 200);
}

private void showAtLocationPopupwindow() {
PopupWindowCompat popupWindow = new PopupWindowCompat(this);
View contentView = LayoutInflater.from(this).inflate(R.layout.ppw_layout, null);
popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setContentView(contentView);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAtLocation(btn_at_location, Gravity.CENTER, 0, 0);
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
android:layout_marginTop="16dp"
android:text="高度为固定值"/>

<Button
android:id="@+id/btn_at_location"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginTop="16dp"
android:text="高度为wrap_content, showAtLocation"/>

</LinearLayout>
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.novoda:bintray-release:0.9'
classpath 'com.novoda:bintray-release:0.9.1'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Jul 29 17:00:12 CST 2018
#Mon Dec 03 18:08:27 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
13 changes: 7 additions & 6 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26
compileSdkVersion 29



defaultConfig {
minSdkVersion 15
targetSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

}

Expand All @@ -21,15 +21,16 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '29.0.3'

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

apply plugin: 'com.novoda.bintray-release'
Expand All @@ -39,7 +40,7 @@ publish {
groupId = 'com.jankin.popupwindowcompat'
artifactId = 'lib'
uploadName = 'PopupWindowCompat'
publishVersion = "1.0.3"
publishVersion = "1.0.4"
desc = 'a compat library for PopupWindow'
website = 'https://github.com/wang0826jj/PopupWindowCompat'
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jankin.study.lib;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
Expand Down Expand Up @@ -68,11 +67,11 @@ public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
// 获取控件在屏幕的位置
anchor.getLocationOnScreen(location);
// 算出popwindow最大高度
int maxHeight = screenHeight - location[1] - anchor.getHeight();
int maxHeight = screenHeight - location[1] - anchor.getHeight() - yoff;
// popupwindow 有具体的高度值,但是小于anchor下边缘与屏幕底部的距离, 正常显示
if(getHeight() > 0 && getHeight() < maxHeight){
if (getHeight() > 0 && getHeight() < maxHeight) {
showCompatSuper(anchor, xoff, yoff, gravity);
}else {
} else {
// match_parent 或者 popwinddow的具体高度值大于anchor下边缘与屏幕底部的距离, 都设置为最大可用高度
setHeight(maxHeight);
showCompatSuper(anchor, xoff, yoff, gravity);
Expand Down

0 comments on commit eeb05f7

Please sign in to comment.