Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. ImageButton imageButton = new ImageButton(this);
  2. imageButton.setBackgroundColor(getResources().getColor(android.R.color.transparent));
  3.  
  4. File file = new File("caminho para a imagem");
  5. Bitmap bmImg = BitmapFactory.decodeFile(file.getPath());
  6. imageButton.setImageBitmap(bmImg);
  7.  
  8. //Se quiser algum tamanho especifico
  9. ViewGroup.LayoutParams layoutParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  10. imageButton.setLayoutParams(layoutParams);
  11.  
  12. //aí você adiciona essa imagem onde quiser, num ViewGroup
  13. layoutPai.addView(imageButton);
  14.  
  15. <?xml version="1.0" encoding="utf-8"?>
  16. <ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. android:background="@android:color/transparent"
  20. android:id="@+id/imageButton" />
  21.  
  22. ImageButton imageButton = (ImageButton)LayoutInflater.from(this).inflate(R.layout.imagebutton, null);
  23.  
  24. File file = new File("caminho para a imagem");
  25. Bitmap bmImg = BitmapFactory.decodeFile(file.getPath());
  26. imageButton.setImageBitmap(bmImg);
  27.  
  28. //aí você adiciona essa imagem onde quiser, num ViewGroup
  29. layoutPai.addView(imageButton);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement