(1)style内容
<style name="MyDialogStyleBottom" parent="android:Theme.Dialog">
<item name="android:windowAnimationStyle">@style/AnimBottom</item>
<item name="android:windowFrame">@null</item>
<!-- 边框 -->
<item name="android:windowIsFloating">true</item>
<!-- 是否浮现在activity之上 -->
<item name="android:windowIsTranslucent">true</item>
<!-- 半透明 -->
<item name="android:windowNoTitle">true</item>
<!-- 无标题 -->
<item name="android:windowBackground">@android:color/transparent<item>
<!-- 背景透明 -->
<item name="android:backgroundDimEnabled">true</item> </style>
(2)activity中oncreate()中设置setContentView(R.layout.activity_pick_picture);
getWindow().setLayout(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT);
2.dialog 全屏显示:
(1)style 内容:
<style name="MyDialogStyleBottom" parent="android:Theme.Dialog">
<item name="android:windowAnimationStyle">@style/AnimBottom</item>
<item name="android:windowFrame">@null</item>
<!-- 边框 -->
<item name="android:windowIsFloating">true</item> <!-- 是否浮现在activity之上 -->
<item name="android:windowIsTranslucent">true</item> <!-- 半透明 -->
<item name="android:windowNoTitle">true</item> <!-- 无标题 -->
<item name="android:windowBackground">@android:color/transparent<item> <!-- 背景透明 -->
<item name="android:backgroundDimEnabled">true</item> </style>
(2)dialog show()中设置 public void show() {
super.show();
DisplayMetrics displayMetrics =getWindow().getContext().getResources().getDisplayMetrics();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)mContentView.getLayoutParams();
layoutParams.width = displayMetrics.widthPixels; layoutParams.height = displayMetrics.heightPixels;
mContentView.setLayoutParams(layoutParams);
}//mContentView 为dialog xml布局文件view
3.activity 背景透明
(1)style 内容:
<style name="Transparent">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Activity</item>
<item name="android:activityOpenEnterAnimation">@anim/slide_in_left</item>
<item name="android:activityCloseEnterAnimation">@anim/slide_in_left</item>
<item name="android:activityOpenExitAnimation">@anim/slide_out_right</item>
<item name="android:activityCloseExitAnimation">@anim/slide_out_right</item> </style>
4.activity 关闭系统动画
(1)style 内容:
<style name="notAnimation">
<item name="android:activityOpenEnterAnimation">@null</item>
<item name="android:activityOpenExitAnimation">@null</item>
<item name="android:activityCloseEnterAnimation">@null</item>
<item name="android:activityCloseExitAnimation">@null</item>
<item name="android:taskOpenEnterAnimation">@null</item>
<item name="android:taskOpenExitAnimation">@null</item>
<item name="android:taskCloseEnterAnimation">@null</item>
<item name="android:taskCloseExitAnimation">@null</item>
<item name="android:taskToFrontEnterAnimation">@null</item>
<item name="android:taskToFrontExitAnimation">@null</item>
<item name="android:taskToBackEnterAnimation">@null</item>
<item name="android:taskToBackExitAnimation">@null</item> </style>
(2)activity onCreate()中设置getWindow().setWindowAnimations(R.style.notAnimation);(3) 1)slide_out_right.xml 右边滑出动画
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate android:duration="@android:integer/config_activityDefaultDur" android:fromXDelta="0.0" android:toXDelta="-100.0%p" />
</set>
2)slide_in_left.xml 左边滑入动画<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate android:duration="@android:integer/config_activityDefaultDur" android:fromXDelta="-100.0%p" android:toXDelta="0.0" />
</set>
5.androidAPI22以上 apache 包不兼容的问题
build.gradle 中android{.........
useLibrary 'org.apache.http.legacy'
……………
}
6. androidStudio 2.0 以上的配置NDK
1)配置NDK路径
2)下载NDK编译工具(setting中)
3)下载NDK插件
4)build.gradle中配置:
defaultConfig {
……………….
multiDexEnabled true
ndk {
moduleName "DBHelper”//对应so库的名字 //
moduleName "CipherUtils"
stl "gnustl_static" // stlport_static
abiFilters "armeabi", "armeabi-v7a"
ldLibs "log", "android"
}
}……………………………….
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
5)gradle.properties中添加android.useDeprecatedNdk=true7.View 中绘制其它view(被绘制的view 不是View的children),需要现在onlayout中先行layout,否则该view在即使绘制了也不会显示
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (mPlayIV != null){
mPlayIV.layout(0,0,80,80);
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
canvas.save();
int width = getMeasuredWidth();
int height = getMeasuredHeight();
canvas.translate((width-80)/2, (height-80)/2);//平移画布区域,用于绘制其它view
canvas.clipRect(0, 0, 80, 80);
canvas.saveLayerAlpha(0, 0, 80, 80, 255, Canvas.ALL_SAVE_FLAG);
mPlayIV.draw(canvas);
canvas.restore();
canvas.restore();
}
8.AndroidStudio在c++代码中引用外部so库的方法,使用环境为androidstudio2.0以上,ndk r10
(1)编译好需要使用的so库
(2) 将so库copy到项目 libs/armeabi 目录下
(3) 将so库copy到ndk存放so库的目录下
(4) 将so库对应的头文件(.h文件)拷贝到ndk存放头文件的目录下
(5) 在build.gradle 中配置加上需要动态链接的库,例如:(参照搭建ndk环境)
ndk {
moduleName "CipherUtils"
stl "gnustl_static" // stlport_static
abiFilters "armeabi", "armeabi-v7a"
ldLibs "log", "android","sqlite","DBHelper”//(这里的DBHelper为编译好的so库)
}
(6)错误问题及解决方法:1)当使用外部so库时,编译时 提示 找不到 某某 函数的定义。(如果编译环境为C++,而so库为C编译出来,此时在导入头文件时应加上
extern “C” 例如:extern “C” {#include <libavutil/avutil.h>}
9.imageview 图片自适应
<ImageView
android:id="@+id/iv14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>
10.关于部分64位的机器找不到so库的问题(某某.so not found)
解决方案:修改build.gradle 脚本
1. 修改编译版本,如下:
compileSdkVersion 22
buildToolsVersion "22.0.1"
// useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.hohistar.atoobo"
minSdkVersion 15
targetSdkVersion 22
}
2.过滤so库目录
defaultConfig {
ndk {
abiFilters "armeabi"
}}
3.设置so库目录
android {
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
4.向gradle.properties尾行添加android.useDeprecatedNdk=true