Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] Ajuda para pegar valores de width e height do componente ImageButton

eu uso uma ImageButton... é que preciso pegar o width e o height do ImageButton e setar isso na imagem... pra deixar adaptavel para qualquer tela de celular


Em 25 de março de 2013 21:21, Jade Costa <jademcosta@gmail.com> escreveu:
Vc poderia não usar um botão. Poderia usar um ImageButton (ou ImageView), por exemplo, e assim usar o método scaleType dele, que irá redimensionar a sua foto...

Abraço,

Em 25 de março de 2013 17:45, Ricardo Cardoso <rick.duk@gmail.com> escreveu:
Olá, fiz o seguinte layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical"

    android:gravity="center"

    android:background="#302119" >


    

    <LinearLayout

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:layout_weight="1"

    android:orientation="horizontal" >


    <ImageButton

        android:id="@+id/btn_foto"

        android:gravity="center"

        android:layout_width="0dp"

        android:layout_height="fill_parent"

        android:layout_weight="1"

        android:layout_marginBottom="1dp" />

    

    <ImageButton

        android:id="@+id/btn_galeria"

        android:src="@drawable/btn_galeria"

        android:gravity="center"

        android:layout_width="0dp"

        android:layout_height="fill_parent"

        android:layout_weight="1"

        android:background="#4c3828"

        android:layout_marginLeft="1dp"

        android:layout_marginBottom="1dp" />


    </LinearLayout>

    

<LinearLayout

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:orientation="horizontal" 

    android:layout_weight="1">


    <ImageButton

        android:id="@+id/btn_seila"

        android:src="@drawable/btn_seila"

        android:layout_weight="1"

        android:layout_width="0dp"

        android:layout_height="fill_parent"

        android:background="#4c3828"

        android:layout_marginBottom="1dp"/>


    <ImageButton

        android:id="@+id/btn_seila2"

        android:src="@drawable/btn_seila2"

        android:layout_width="0dp"

        android:layout_height="fill_parent"

        android:layout_weight="1"

        android:background="#4c3828"

        android:layout_marginLeft="1dp"

        android:layout_marginBottom="1dp"/>

    </LinearLayout>

</LinearLayout>


Como podem ver, são 4 botões, todos do mesmo tamanho... 

Só que um botão, o btn_foto eu queria que o background dele fosse uma foto tirada da camera, mas se faço isso o layout quebra todo, por causa da foto que é maior.

Eu preciso pegar o tamanho do botão e setar na foto, já tentei fazer isso, porém o botão da "aumentando" até chegar ao limite de layout inteiro...


fiz da seguinte maneira


ViewTreeObserver vto = btn_foto.getViewTreeObserver();

vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

@Override

public void onGlobalLayout() {

if(mDAO.retornaPathFoto() != null){

bm = BitmapFactory.decodeFile(mDAO.retornaPathFoto());

bm = Bitmap.createScaledBitmap(bm, btn_foto.getWidth(), btn_foto.getHeight(), false);

}else{

bm = BitmapFactory.decodeResource(getResources(), R.drawable.btn_seila);

}

btn_foto.setImageBitmap(bm);

}

});


Alguém pode me dizer se tem alguma maneira de fazer isso??

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Jade Moreira da Costa

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário