2011-02-09 2 views
1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#444548"> 

    <ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/image" 
    > 
    </ImageView> 

    <TextView android:id="@+id/TextView01" 
android:textColor="#ffffff" 
android:layout_width="wrap_content" 
android:text="@+id/TextView01" android:layout_height="wrap_content"> 
</TextView> 


</LinearLayout> 

im appeler mon textview dans ma classe .java comme ceci:appeler un imageView dans ma classe .java

TextView tv1 = (TextView) findViewById(R.id.TextView01); 
    tv1.setText("Welcome to Schogini!"); 

est-il possible de le faire pour une image aussi grâce

Répondre

2

? Oui, vous pouvez créer un objet comme TextView que vous avez fait ci-dessus, et créer un dossier nommé drawable sous le dossier res et placer l'image dont vous avez besoin, et définir l'image image en appelant son identifiant from drawable.

 ImageView im = (ImageView) findViewById(R.id.my_image); 
     im.setImage(R.drawable.name_of_image); 
  • sans l'extension de l'image.
+2

merci! Cela fonctionne mais vous devez le changer en im.setImageResource (R.drawable.icon); –

+0

désolé pour mon erreur –

Questions connexes