Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ImageButton imageButton = new ImageButton(this);
- imageButton.setBackgroundColor(getResources().getColor(android.R.color.transparent));
- File file = new File("caminho para a imagem");
- Bitmap bmImg = BitmapFactory.decodeFile(file.getPath());
- imageButton.setImageBitmap(bmImg);
- //Se quiser algum tamanho especifico
- ViewGroup.LayoutParams layoutParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- imageButton.setLayoutParams(layoutParams);
- //aí você adiciona essa imagem onde quiser, num ViewGroup
- layoutPai.addView(imageButton);
- <?xml version="1.0" encoding="utf-8"?>
- <ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@android:color/transparent"
- android:id="@+id/imageButton" />
- ImageButton imageButton = (ImageButton)LayoutInflater.from(this).inflate(R.layout.imagebutton, null);
- File file = new File("caminho para a imagem");
- Bitmap bmImg = BitmapFactory.decodeFile(file.getPath());
- imageButton.setImageBitmap(bmImg);
- //aí você adiciona essa imagem onde quiser, num ViewGroup
- layoutPai.addView(imageButton);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement