当我们需要将dp转换成px时,一般我们可以自己写,因为也很简单。其实android api当中已经给我们提供了这个方法了。
TypedValue.applyDimension(COMPLEX_UNIT_DIP, 14, context.getResources().getDisplayMetrics());
作用:将14dp转换为px
| from optparse import OptionParser | |
| from getpass import getpass | |
| import base64, hmac, hashlib | |
| ''' | |
| This small script is meant to generate long passwords by hashing a secret | |
| password and a site identifier. The intent is to create a usable interface | |
| for maintaining longer, somewhat more secure (?) passwords. | |
| The idea here is that you remember a 'master' password and use it to generate |
| public class BlankTextDrawable extends Drawable { | |
| private Paint mPaint = new Paint(); | |
| private RectF mRect = new RectF(); | |
| private static final String text = "wenhao"; | |
| private static final int TEXT_SIZE = 40; //sps | |
| private Bitmap mBackgroundBitmap; | |
| private Bitmap mTextBitmap; |
| //代码节选自:Drawable.java createFromXmlInner()方法 | |
| switch (name) { | |
| case "selector": | |
| drawable = new StateListDrawable(); | |
| break; | |
| case "animated-selector": | |
| drawable = new AnimatedStateListDrawable(); | |
| break; | |
| case "level-list": |
| 将dp转换为px时,我们通常的做法: | |
| public static float convertDpToPixel(float dp, Context context){ | |
| final float density = getResources().getDisplayMetrics().density; | |
| return (dp * scale + 0.5f); | |
| } | |
| 那么为什么需要+0.5f呢? | |
| 在官方文档中:http://developer.android.com/guide/practices/screens_support.html |
| //在onCreate当中调用 | |
| main = LayoutInflater.from(this).inflate(R.layout.activity_main, | |
| null); | |
| main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); | |
| setContentView(main); |
| fname = raw_input("Enter file name:") | |
| try: | |
| fobj = open(fname,"r") | |
| except IOError, e: | |
| print 'file open error....' | |
| else: | |
| for eachLine in fobj: | |
| print eachLine, |
| import os | |
| while True: | |
| filename = raw_input("enter filename:") | |
| if(os.path.exists(filename)): | |
| print "%s is already exists" % filename | |
| else: | |
| break | |