- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这是我遇到的问题,在 onCreate() 中,我想最初将 imageview 设置为文件列表中的第一个图像,但是使用 ImageViews 宽度和高度,当它来回翻转时它设置图像到 ImageViews dimentions 没问题,但在 onCreate() 中我得到 IllegalArgumentException 宽度和高度必须大于 0。我试图创建启动方法,如果它没有发生在 onCreate() 中,idk,非常感谢任何帮助,谢谢你的时间
public class ViewFlipperActivity extends Activity {
ViewFlipper page;
Animation animFlipInForeward;
Animation animFlipOutForeward;
Animation animFlipInBackward;
Animation animFlipOutBackward;
String[] imagefiles;
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "how");
int filescount,nowcount;
ImageView image;
Matrix matrix;
Bitmap d;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imagefiles = file.list();
filescount = imagefiles.length;
nowcount = 0;
matrix = new Matrix();
matrix.postRotate(90);
page = (ViewFlipper)findViewById(R.id.flipper);
image = (ImageView)findViewById(R.id.zero);
animFlipInForeward = AnimationUtils.loadAnimation(this, R.anim.left_in);
animFlipOutForeward = AnimationUtils.loadAnimation(this, R.anim.left_out);
animFlipInBackward = AnimationUtils.loadAnimation(this, R.anim.right_in);
animFlipOutBackward = AnimationUtils.loadAnimation(this, R.anim.right_out);
start();
}
private void start(){
d = BitmapFactory.decodeFile(file.toString() +"/" + imagefiles[nowcount]);
d = Bitmap.createBitmap(d, 0, 0, d.getWidth(), d.getHeight(), matrix, true);
System.gc();
d = Bitmap.createScaledBitmap(d, image.getWidth(), image.getHeight(), true);
System.gc();
image.setImageBitmap(d);
System.gc();
}
private void SwipeRight(){
page.setInAnimation(animFlipInBackward);
page.setOutAnimation(animFlipOutBackward);
nowcount--;
if(nowcount < 0)
nowcount = filescount - 1;
d = BitmapFactory.decodeFile(file.toString() +"/" + imagefiles[nowcount]);
d = Bitmap.createBitmap(d, 0, 0, d.getWidth(), d.getHeight(), matrix, true);
System.gc();
d = Bitmap.createScaledBitmap(d, image.getWidth(), image.getHeight(), true);
System.gc();
image.setImageBitmap(d);
System.gc();
page.showPrevious();
Log.d("show previous", "exe");
}
private void SwipeLeft(){
page.setInAnimation(animFlipInForeward);
page.setOutAnimation(animFlipOutForeward);
nowcount++;
if(nowcount > 3)
nowcount = 0;
d = BitmapFactory.decodeFile(file.toString() +"/" + imagefiles[nowcount]);
d = Bitmap.createBitmap(d, 0, 0, d.getWidth(), d.getHeight(), matrix, true);
System.gc();
d = Bitmap.createScaledBitmap(d, image.getWidth(), image.getHeight(), true);
System.gc();
image.setImageBitmap(d);
System.gc();
page.showNext();
Log.d("show next", "exe");
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return gestureDetector.onTouchEvent(event);
}
SimpleOnGestureListener simpleOnGestureListener
= new SimpleOnGestureListener(){
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
float sensitvity = 50;
if((e1.getX() - e2.getX()) > sensitvity){
SwipeLeft();
}else if((e2.getX() - e1.getX()) > sensitvity){
SwipeRight();
}
return true;
}
};
GestureDetector gestureDetector
= new GestureDetector(simpleOnGestureListener);
}
最佳答案
ImageView 的高度和宽度只有在为父 View 请求布局时才会计算,这是在 onCreate
完成之后。你应该实现一个 OnGlobalLayoutListener并从那里获取 ImageView 的高度和宽度。不过,您不应该在其中加载图像,而是使用 AsyncTask
或其他方法将其加载到后台。
关于android - 根据 Imageviews 的高度和宽度在 onCreate() 中创建缩放位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15074578/
在我最新版本的应用程序中,开发者控制台中报告的一些崩溃让我感到抓狂。 它们显示为 java.lang.IllegalStateException 并且似乎 Application.onCreate 在
在阅读《你好,Android》这本书时,我注意到: each java file with onCreate(Bundle savedInstanceState) method, has protec
我对 Android 编程还是个新手,所以这个问题很基础。我在 Internet 上看到很多代码示例,其中 UI 组件(如 TextView)在 Activity 的 onCreate() 方法中被初
在某些情况下,我可以看到 Activity.onCreate 在 Application 对象被创建之前被调用(在 Application.onCreate 被调用之前)。那有可能吗? 最佳答案 可能
我发现 MyApplication#onCreate 和 MyActivity#onCreate 之间有 200 毫秒或更多的延迟。在那段时间里有什么重要的事情发生吗? 最佳答案 根据 Applica
我正在创建一个具有带有 fragment 的抽屉导航 Activity 的应用程序。在应用程序的每次冷启动时,我都会执行一些初始化代码,在其中加载以下内容: 用户 session (无论用户是否登录)
我正在使用处理程序在 onCreate 内部调用 Runnable,并希望通过在 onCreate 外部使用 onBackPressed 来停止它。如何在 onCreate 之外停止 Runnable
在崩溃日志中,我发现了非常奇怪的应用程序错误,该错误发生在 Android 7.0-8.0 上,对于一些少量用户来说,但非常频繁。我无法重现该问题,这里的代码反射(reflect)了当前应用程序的状态
我正在使用 FragmentActivity 和 Fragments。 应用程序启动时: FragmentActivity onCreate() <------ FragmentActivity on
我在 AndroidManifest.xml 中注册了一个 ContentProvider,并且在 Application.onCreate() 之前调用了 ContentProvider.onCre
我希望我的数据库创建一次,它不会改变,但是当我在 onCreate() 时我不能创建数据...... public class EventsData extends SQLiteOpenHelper
最近我遇到了一个难以重现的问题。当 fragment 尝试使用来自 Activity 的数据初始化 ArrayAdapter 时,会发生 NPE。在Activity的onCreate方法中初始化的默认
我尝试通过单击导航从 EditText-Element 添加文本。我尝试在 Java 类中排除对 ListView 元素的访问(其中应添加文本),并在我的主 Activity 中对其进行初始化。如果我
当主 Activity 在安装应用程序后第一次尝试打开数据库时,会触发 SQLiteHelper Oncreate 方法(正如人们所期望的那样)。我想在 OnCreate 中创建数据表后填充数据库,但
我试图更好地理解声明和初始化,但并不真正理解为什么您可以在 OnClick 中更改按钮的文本,即使它无权访问 OnCreate,因为它是另一个函数。 当还在 onCreate 中声明变量时,它不起作用
这很奇怪。我有一个简单的应用程序,一旦登录就会显示 Activity 中的一个 fragment 。该应用程序也有一个不活动的“超时”,在该时间之后它完成 Activity 并显示登录屏幕——如果超时
我在我的 Android 项目中使用 AspectJ,我想编写一个 pointcut 来捕获对 onCreate() 和 的所有调用>onDestroy() 我的 Activity 。我对 Aspec
初始问题 (18/05/2020): 所以最新的更新来自 androidx.fragment:fragment:1.3.0- alpha07 到 androidx.fragment:fragment:
当我的应用程序“在顶部”运行时锁定屏幕时,系统几乎立即调用 onCreate(屏幕仍然是黑色的)。这种破坏性行为的原因可能是什么? 最佳答案 对我来说 android:configChanges="o
我浏览了其他 SO 帖子,但没有找到与我的问题相关的任何内容。 我正在尝试创建一个应用程序,该应用程序将获取用户上次重新启动后的步数。这是我的主要 Activity : package com.ass
我是一名优秀的程序员,十分优秀!