小编zeg*_*nus的帖子

Android字符按字符显示文本动画

任何人都知道执行动画的任何有效方法,必须做的是逐个字符地显示文本,如:

T
Th
Thi
This
This i
这是
......

等等.

谢谢!

animation android text character

38
推荐指数
3
解决办法
4万
查看次数

Android alpha动画fadein fadeout有延迟

我想做一个非常简单的alpha动画,但我找不到有效的方法.

我们的想法是在视图上执行此动画:

  1. alpha从0到1的1秒
  2. 将alpha保持在1为5秒
  3. alpha从1到0的1秒
  4. 将alpha保持在0持续5秒.
  5. 从1开始.

我试图用AnimationSet实现它:

AnimationSet animationSet = new AnimationSet(true);

Animation animation1 = new AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
animation1.setDuration(1000);

Animation animation2 = new AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
animation2.setDuration(1000);
animation2.setStartOffset(5000);

Animation animation3 = new AlphaAnimation(0.0f, 0.0f);
animation3.setDuration(4000)
animation3.setStartOffset(6000);

animationSet.add(animation1);
animationSet.add(animation2);
animationSet.add(animation3);
Run Code Online (Sandbox Code Playgroud)

等等..

但它接下来第三个动画与所有的alpha动画混乱,我认为这导致Android管理这种类型的动画的方式内​​部不连贯.

任何的想法?

谢谢.

animation android alpha fadeout fadein

37
推荐指数
2
解决办法
7万
查看次数

Android下载大文件

我正在尝试从Web服务器下载一个大的.zip文件,但我有一个奇怪的行为,描述是:

  • 我正在设备模拟器中执行代码,API级别3(版本1.5),SD卡为512MB.我用"擦除数据用户"启动设备
  • conexion.getContentLength()的大小长度为7012725
  • 服务器地址是localhost(10.0.2.2),但我尝试使用外部服务器,行为是相同的.我已经仔细检查过我可以通过网络浏览器下载文件.
  • 我在清单文件中有这些权限:

-

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
Run Code Online (Sandbox Code Playgroud)

错误:

  • 它开始下载文件,我可以看到文本10,20,30,40,50,然后它停在60.
  • 过了一会儿,模拟器重新启动.

解决方法:

  • stackoverflow中的这个问题在设备中工作,而不是在我的情况下.
  • 关于这个wifi锁定问题,我所做的是添加此权限"android.permission.WAKE_LOCK"然后这段代码,但具有完全相同的行为:

    WifiManager.WifiLock wifilock; WifiManager manager =(WifiManager)getSystemService(Context.WIFI_SERVICE); wifilock = manager.createWifiLock("wifilock"); wifilock.acquire(); ... wifilock.release();

这是代码,它正在一个单独的线程中执行:

private void downloadData(){
    try{
        Log.v(TAG, "downloading data");

        URL url  = new URL("http://10.0.2.2/1.zip");
        URLConnection connection = url.openConnection();
        connection.connect();

        int lenghtOfFile = connection.getContentLength();

        Log.v(TAG, "lenghtOfFile = "+lenghtOfFile);

        InputStream is = url.openStream();

        File testDirectory = new File(Environment.getExternalStorageDirectory()+"/testDirectory/");
    if(!testDirectory.exists()){
        testDirectory.mkdir();
    }

        FileOutputStream fos = new FileOutputStream(testDirectory+"/files.zip");

        byte data[] = new byte[1024];

        int …
Run Code Online (Sandbox Code Playgroud)

android download

13
推荐指数
1
解决办法
1万
查看次数

Android后向代码兼容性

我正在开发一个使用的应用程序

android.hardware.Camera.parameters.getSupportedPictureSizes()

这仅适用于SDK版本8,我希望与SDK 4兼容,所以我这样做了:

if(Build.VERSION.SDK_INT> = 8){...}

但是在模拟器上,它会尝试检查对此函数的引用,并且它会失败:

02-02 11:20:10.930:ERROR/dalvikvm(1841):找不到方法android.hardware.Camera $ Parameters.getSupportedPictureSizes,从方法com.test.demo.CameraCustom.takeAPicture中引用

有关如何解决此向后兼容性问题的任何想法?

我试图在surfaceChanged中使用这段代码进行墨迹分配.显然,代码可以在没有调用的情况下直接工作:

try{
    windowmanager_defaultdisplay_Rotation = getWindowManager().getDefaultDisplay().getClass().getMethod("getRotation");
    Log.v(MainMenu.TAG, "getRotation exist");
}catch(Exception e){
    Log.v(MainMenu.TAG, "getRotation dont exist");
}

try{
    windowmanager_defaultdisplay_Rotation.invoke(null, null);
    Log.v(MainMenu.TAG, "getRotation invoking ok, rotation ");
}catch(Exception e){
    Log.v(MainMenu.TAG, "exception invoking getRotation "+e.toString());
}
Run Code Online (Sandbox Code Playgroud)

我得到"getRotation exists"但是"异常调用getRotation java.lang.NullPointerException.

任何的想法?

android backwards-compatibility

7
推荐指数
1
解决办法
3799
查看次数

android mediaplayer永远在ICS上循环播放

我想播放一个通知声音,我的问题是声音永远循环,它应该只响一次.

我尝试了两种方法:

notification.sound = Uri.parse("content://media/internal/audio/media/38");
Run Code Online (Sandbox Code Playgroud)

mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
mMediaPlayer.setDataSource(this, Uri.parse("content://media/internal/audio/media/38"));
mMediaPlayer.setLooping(false);
mMediaPlayer.prepare();
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        Log.v(Utils.TAG, "onprepared");
        mp.start();
    }
});

mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
    @Override
    public void onCompletion(MediaPlayer mp) {
        Log.v(Utils.TAG, "end, we should release");
        mp.stop();
        mp.release();
    }
});
Run Code Online (Sandbox Code Playgroud)

在第二种情况下,我从未看到跟踪"结束,我们应该释放",音频一遍又一遍地播放.

任何的想法?

非常感谢你

更新:

我尝试了两种设备:

  • 它在ICS 4.0.4的Galaxy Nexus上永远循环
  • 它适用于HTC Hero 2.2.1

notifications android loops media-player

7
推荐指数
2
解决办法
1262
查看次数

Android RuntimeException onCreateDialog没有为id创建对话框

我有一个应用程序,您可以显示和关闭几个对话框:

showDialog(...)
removeDialog(...)
Run Code Online (Sandbox Code Playgroud)

我在应用程序中玩了一下,当屏幕上没有任何Dialog时,我按下菜单按钮,然后进入主安卓屏幕.

过了一会儿,我再次进入我的应用程序,有时,我得到这个RuntimeException:

java.lang.IllegalArgumentException: Activity#onCreateDialog did not create a dialog for id 4
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
    at android.app.ActivityThread.access$2200(ActivityThread.java:126)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4595)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Activity#onCreateDialog did not create a dialog for id 4
    at android.app.Activity.createDialog(Activity.java:878)
    at android.app.Activity.restoreManagedDialogs(Activity.java:867)
    at android.app.Activity.performRestoreInstanceState(Activity.java:815)
    at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1096)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2565)
    ... 11 more
Run Code Online (Sandbox Code Playgroud)

任何的想法?

非常感谢你.

更新,更多信息:

当前的onCreateDialog实现是:

protected Dialog onCreateDialog(int id){
 Builder b = new AlertDialog.Builder(this);
 if(id …
Run Code Online (Sandbox Code Playgroud)

android runtimeexception

6
推荐指数
2
解决办法
7116
查看次数

优化contentProvider查询以检索联系人姓名和电话

目前,我正在使用以下代码来获取联系人姓名和电话号码:

    ContentResolver contentResolver = getContentResolver();

    Cursor people = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

    int nameIndex = people.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
    int idIndex = people.getColumnIndex(ContactsContract.Contacts._ID);
    int hasPhoneNumberIndex = people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);

    String name, id;
    int hasPhoneNumber;

    while(people.moveToNext()){
        name = people.getString(nameIndex);
        id = people.getString(idIndex);
        hasPhoneNumber = people.getInt(hasPhoneNumberIndex);

        if(hasPhoneNumber > 0){
            Cursor phones = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+id, null, null);
            phones.moveToFirst();

            int phoneIndex = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
            String phone = phones.getString(phoneIndex);

            HashMap<String, String> namePhoneType = new HashMap<String, String>();
            namePhoneType.put("Name", name);
            namePhoneType.put("Phone", phone);

            m_peopleList.add(namePhoneType);

            phones.close();
        }
    }
Run Code Online (Sandbox Code Playgroud)

但这非常慢。

是否只有一种查询方式才能检索姓名和电话?

android contacts android-contentprovider

2
推荐指数
1
解决办法
2851
查看次数