android琐碎笔记三

1.当你要旋转一个animition时 你会发现如果你只用rotate 它是不平滑的 旋转360度之后它会滞留一会 然后再转 给人感觉是暂停那么一会 怎么消除呢?这是因为如果只用rotate
它默认使用了android:anim/accelerate_interpolator,所以你要写一个自己的interpolator ,这个interpolator就是linearInterpolator。
所以你必须先建一个res/anim/linear_interpolator.xml:

<?xml version="1.0" encoding="utf-8"?><linearInterpolator xmlns:android="http://schemas.android.com/apk/res/android" />

然后在你的animition中加入
android:iterpolator="@anim/linear_interpolator"这句话就可以了

如:
<?xml version="1.0" encoding="UTF-8"?><rotate    xmlns:android="http://schemas.android.com/apk/res/android"    android:fromDegrees="0"    android:toDegrees="360"    android:pivotX="50%"    android:pivotY="50%"    android:repeatCount="infinite"    android:duration="1200" />

默认的是accelerate_interpolator,所以你必须在上面的xml中加入
android:iterpolator="@anim/linear_interpolator"
然后就是平滑的旋转了。

2.当采用过滤的方法:
final TextWatcher textChecker = new TextWatcher() {   
   public void afterTextChanged(Editable s) {}  
    public void beforeTextChanged(CharSequence s, int start, int count,  int after) {}  
     public void onTextChanged(CharSequence s, int start, int before,   int count) {      
      filterData(search.getText().toString());   
      }
      };
     
      private void filterData(String textinput){      
       mCursor = mHelperData.searchData(textinput);      
        startManagingCursor(mCursor);      
         String[] from = new String[]{ MyData.KEY_ROWID,                     
           MyData.KEY_TITLE, MyData.KEY_DESCRIPTION };       
           int[] to = new int[]{ R.id.id, R.id.title, R.id.description, R.id.icon };                     
            setListAdapter(new MyAdapter(this, R.layout.list_row, mCursor, from, to ));}

3. 直接发起一个相关的联系人:
Intent intent = new Intent();intent.setAction(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
Intent dialIntent = new Intent( "android.intent.action.DIAL",Uri.parse("tel:666444666")); startActivity(dialIntent);

4.字符串空格以及字符串参数的问题
<string name="Toast_Memory_GameWon_part1">you found ALL PAIRS ! on\ </string><string name="Toast_Memory_GameWon_part2">\ flips !</string>
想在字符串前面和后面有空格一定要注意转义

String message_all_pairs_found = getString(R.string.Toast_Memory_GameWon_part1)+"total_flips"+getString(R.string.Toast_Memory_GameWon_part2);
那么也可以如下实现:
<string name="Toast_Memory_GameWon">you found ALL PAIRS ! on %d flips !</string>
String message_all_pairs_found = String.format(getString(R.string.Toast_Memory_GameWon), total_flips);

5.onKeyDown不起作用 主要因为 可能没有设置setFocusableInTouchMode(true)
最好也加上 setFocusable(true)

6.只知道包名的不知道 R.id的解决办法:
getResources().getIdentifier()
当然你最好吧这个文件放在res/raw/myDataFile 然后读取

7.播放序曲简单方法:
private void playIntro(){        setContentView(R.layout.intro);        VideoView video = (VideoView) this.findViewById(R.id.VideoView01);        Uri uri = Uri.parse("android.resource://real.app/" + R.raw.intro);        video.setVideoURI(uri);        video.requestFocus();        video.setOnCompletionListener(this);        video.start();      }

8. 用流加载图片
BufferedInputStream buf = new BufferedInputStream(mContext.openFileInput(value));Bitmap bitmap = BitmapFactory.decodeStream(buf);

9.自定义一个dialog
class MyDialog extends AlertDialog {    
     public MyDialog(Context ctx) {       
       super(ctx);       
        LayoutInflater factory = LayoutInflater.from(context);      
         View view = factory.inflate(R.layout.dialog_layout, null);       
          setView(view);       
           setTitle("MyTitle");      
            setIcon(R.drawable.myicon);    
            }
            }

10. 邮件发送图片
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
      sendIntent.setType("jpeg/image");   
      sendIntent.putExtra(Intent.EXTRA_EMAIL, "[email protected]");   
      sendIntent.putExtra(Intent.EXTRA_SUBJECT, "aadjfk");   
      sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName));   
      sendIntent.putExtra(Intent.EXTRA_TEXT, sEmailBody); 
       startActivity(Intent.createChooser(sendIntent, "Email:"));

一定要注意"file://"是两个斜杠

11. 播放视频 htc和其他大部分手机在播放视频时 有些不同
tostart = new Intent(Intent.ACTION_VIEW);
       tostart.setDataAndType(Uri.parse(movieurl), "video/*");
       startActivity(tostart);
在大部分手机上是
tostart.setClassName("com.android.camera","com.android.camera.MovieView");
而在htc上
tostart.setClassName("com.htc.album","com.htc.album.ViewVideo");
因此你需要判断
private boolean isCallable(Intent intent) {   
          List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
          return list.size() > 0;
          }

  final Intent intent = new Intent("com.android.camera.action.CROP");
          intent.setClassName("com.android.camera", "com.android.camera.CropImage");
          if (isCallable(intent)) {    // call the intent as you intended.}
          else {    // make alternative arrangements.}

你可能感兴趣的:(android,xml,HTC,Gmail,360)