我想在ViewFlipper上添加ImageView并尝试此代码
ViewFlipper flipVertical = (ViewFlipper)findViewById(R.id.slideVer);
Bitmap bitmap = BitmapFactory.decodeFile("sdcard/vm/picture/vertical/VB-Logo.png");
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(bitmap);
flipVertical.addView(imageView);
对该代码没有任何影响,与我使用
时相同ViewFlipper flipVertical = (ViewFlipper)findViewById(R.id.slideVer);
Uri uriImage = Uri.parse("file:///sdcard/vm/picture/vertical/VB-Logo.png");
imageView.setImageURI(uriImage);
flipVertical.addView(imageView);
我该怎么办? :(
答案 0 :(得分:0)
你可以尝试如下......
ViewFlipper flipVertical = (ViewFlipper)findViewById(R.id.slideVer);
Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getPath() + "/vm/picture/vertical/VB-Logo.png");
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(bitmap);
flipVertical.addView(imageView, params);
如果您没有添加访问SDCard的权限,请在Manifest.xml
文件中添加这些权限...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />