1. img.getLayoutParams().width//代碼設置控件寬度java
String path = Environment.getExternalStorageDirectory()+"/path/";//在SD卡創建文件夾android
2.app
dialog背景透明dom
Window window = dialog.getWindow();iphone
WindowManager.LayoutParams lp = window.getAttributes();ide
lp.alpha = 0.6f;this
window.setAttributes(lp);spa
3..net
//獲取手機全部圖片設計
//只查詢jpeg和png的圖片
Cursor mCursor = mContentResolver.query(mImageUri, null,
MediaStore.Images.Media.MIME_TYPE + "=? or "
+ MediaStore.Images.Media.MIME_TYPE + "=?",
new String[] { "image/jpeg", "image/png" }, MediaStore.Images.Media.DATE_MODIFIED);
while (mCursor.moveToNext()) {
}
4.
//獲取圖片的路徑
String path = mCursor.getString(mCursor
.getColumnIndex(MediaStore.Images.Media.DATA));
//獲取該圖片的父路徑名
String parentName = new File(path).getParentFile().getName();
5.
/* *Button背景 * **/
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
//表示當前視圖是否處於正在交互的窗口中,這個值由系統自動決定,應用程序不能進行改變。
<item android:state_window_focused="false"><shape>
<corners android:radius="10px" />
<padding android:bottom="5px" android:left="30px" android:right="30px" android:top="5px" />
<stroke android:width="1px" android:color="#FF625B" />
<solid android:color="#FF625B" />
</shape></item>
//表示當前視圖得到到焦點,當前視圖是否處於按下狀態
<item android:state_focused="true" android:state_pressed="true"><shape>
<corners android:radius="10px" />
<padding android:bottom="5px" android:left="30px" android:right="30px" android:top="5px" />
<stroke android:width="1px" android:color="#FF625B" />
<solid android:color="#FFC0BE" />
</shape></item>
//表示當前視圖沒有得到到焦點,當前視圖是否處於按下狀態
<item android:state_focused="false" android:state_pressed="true"><shape>
<corners android:radius="10px" />
<padding android:bottom="5px" android:left="30px" android:right="30px" android:top="5px" />
<stroke android:width="1px" android:color="#FF625B" />
<solid android:color="#FFC0BE" />
</shape></item>
//表示當前視圖處於選中狀態
<item android:state_selected="true"><shape>
<corners android:radius="10px" />
<padding android:bottom="5px" android:left="30px" android:right="30px" android:top="5px" />
<stroke android:width="1px" android:color="#FF625B" />
<solid android:color="#FFC0BE" />
</shape></item>
<item android:state_focused="true"><shape>
<corners android:radius="10px" />
<padding android:bottom="5px" android:left="30px" android:right="30px" android:top="5px" />
<stroke android:width="1px" android:color="#FF625B" />
<solid android:color="#FFC0BE" />
</shape></item>
</selector>
邊角弧度:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的顏色 -->
<solid android:color="#FFFFFF" />
<!-- 設置按鈕的四個角爲弧形 -->
<!-- android:radius 弧形的半徑 -->
<corners android:radius="15px" />
</shape>
6.
//在app目錄下建立文件夾
File file = this.getExternalFilesDir(Environment.DIRECTORY_PICTURES); files = new File(file,path); if (!files.exists()){ files.mkdir(); Log.e("tag",files.toString()); }
7.
//屏幕寬高
int width = c.getResources().getDisplayMetrics().widthPixels;
int height = c.getResources().getDisplayMetrics().heightPixels;
8.
狀態欄高度
private int getStatusBarHeight() {
Class<?> c = null;
Object obj = null;
//java.lang.reflect.Field
Field field = null;
int x = 0, sbar = 0;
try {
c = Class.forName("com.android.internal.R$dimen");
obj = c.newInstance();
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
sbar = getContext().getResources().getDimensionPixelSize(x);
} catch (Exception e1) {
e1.printStackTrace();
}
return sbar;
}
9.
獲取文件名:不帶後綴
public String getFileNameNoEx(String filename) { if ((filename != null) && (filename.length() > 0)) { int dot = filename.lastIndexOf('.'); if ((dot >-1) && (dot < (filename.length()))) { return filename.substring(0, dot); } } return filename;
byte[] 流轉化文件
private void createFileWithByte(byte[] bytes) { // TODO Auto-generated method stub /** * 建立File對象,其中包含文件所在的目錄以及文件的命名 */ File file = new File(Environment.getExternalStorageDirectory(), "2017_06_21.3gp");//2017_06_21.3gp是文件格式 // 建立FileOutputStream對象 FileOutputStream outputStream = null; // 建立BufferedOutputStream對象 BufferedOutputStream bufferedOutputStream = null; try { // 若是文件存在則刪除 if (file.exists()) { file.delete(); } // 在文件系統中根據路徑建立一個新的空文件 file.createNewFile(); // 獲取FileOutputStream對象 outputStream = new FileOutputStream(file); // 獲取BufferedOutputStream對象 bufferedOutputStream = new BufferedOutputStream(outputStream); // 往文件所在的緩衝輸出流中寫byte數據 bufferedOutputStream.write(bytes); // 刷出緩衝輸出流,該步很關鍵,要是不執行flush()方法,那麼文件的內容是空的。 bufferedOutputStream.flush(); } catch (Exception e) { // 打印異常信息 e.printStackTrace(); } finally { // 關閉建立的流對象 if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } if (bufferedOutputStream != null) { try { bufferedOutputStream.close(); } catch (Exception e2) { e2.printStackTrace(); } } } }
文件轉byte[]流
public byte[] readStream(String imagepath) throws Exception { FileInputStream fs = new FileInputStream(imagepath); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while (-1 != (len = fs.read(buffer))) { outStream.write(buffer, 0, len); } outStream.close(); fs.close(); return outStream.toByteArray(); }
10.
信任全部的Https請求
s_sSLContext.init(null, new TrustManager[]{new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
}
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
}
}}, new SecureRandom());
11.
jarsigner -verbose -keystore d:\FYRCB.jks -signedjar d:\signed.apk d:\tap_unsign.apk FYRCB
12.
PopupWindow
推薦用showAsDropDwon方法。
這裏是爲了讓PopupWindow居中顯示,因此須要本身定義橫向位移偏移量(其餘位置相似)
int xoff = window.getWidth()/2-parent.getWidth()/2; window.update(); window.showAsDropDown(parent, -xoff, 0);
13.
設計師經常並無針對安卓設備單獨作一套設計稿,而是選擇了iphone手機做爲參考機型。他們覺得適配了IOS就等於適配了安卓。標註尺寸單位都是px。設計帥經常拿iphone6(s)或者是iphone6(s) plus做爲參考機型,一個4.7寸一個5.5寸。好比是4.7英寸的iphone6,它的分辨率是1334x750(dpi是326),而安卓設備最接近這個數值的分辨率是1280*720,對應這個分辨率的dpi通常是320,跟iphone 6(s)很接近,那麼UI使用的iphone6(s)設計稿就對應安卓1280x720(dpi是320)的設備,因此咱們就用320這個dpi進行換算。再好比是5.5英寸的iphone6 plus,它的分辨率是1920x1080(dpi是480),而安卓設備恰好也有不少同等的分辨率,對應這個分辨率的dpi通常是480,而iphone6 plus的dpi也是480,因此咱們用480的dpi進行換算。
舉個例子,設計師基於iphone6的設計稿標註20px,換算成dp就是20x/(320/160)=20/2=10。也就是除以2獲得dp。若是設計師基於iphone6 plus的設計稿標註120px,那麼dp就是120x/(480/160)=30/3=40。也就是除以3獲得dp。
通常咱們看UI稿的尺寸就能夠推測出它的參考機型,好比UI稿的尺寸是1334x750,那確定是iphone6(s)一類的機型,或者是1920x1080,那就是iphone6(s) plus一類的機型。若是UI稿的尺寸匹配不到一款主流的機型,那就是UI設計師不合格啦!