2012-07-12 3 views
0

Я пытаюсь установить фоновое изображение ImageView на другой макет. Другой макет - это макет таблицы. Вот кодУстановить изображение для ImageView на другом макете

ImageView pdfImage; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.help); 

    LayoutInflater inflater = (LayoutInflater) context.getSystemService 
     (Context.LAYOUT_INFLATER_SERVICE); 
    LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.listlayout, null); 
    pdfImage = (ImageView)ll.findViewById(R.id.pdfImage); 

    pdfImage.setBackgroundResource(R.drawable.pdflogo); 

pdflogo не получает устанавливается изображение. Это просто пусто. Как я могу это сделать?

<?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:orientation="vertical" > 

<RelativeLayout android:layout_width="wrap_content" android:layout_height="50dp">  
    <ImageView android:id="@+id/selfImage" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/selfhelpnavbar"/> 
    <ImageView android:id="@+id/logoImage" android:layout_width="70dp" android:layout_height="46dp" android:layout_alignParentTop="true" android:layout_alignParentRight="true" /> 
    <ImageView android:id="@+id/mainLogo" android:layout_width="50dp" android:layout_height="46dp" android:background="@drawable/mainlogo" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"/> 
</RelativeLayout> 

    <ListView 
     android:id="@+id/helpList" 
     android:layout_width="wrap_content" 
     android:layout_height="387dp" > 
    </ListView> 

<!-- Tab Bar --> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

    <ImageButton 
     android:id="@+id/helpButton" 
     android:layout_width="0.0dip" 
     android:layout_height="fill_parent" 
     android:background="@drawable/selfhelptab_selected" 
     android:layout_weight="1.0" 
     android:onClick="onClick" 
     android:clickable="true"/> 

    <ImageButton 
     android:id="@+id/eButton" 
     android:layout_width="0.0dip" 
     android:layout_height="fill_parent" 
     android:background="@drawable/eapservicestab" 
     android:layout_weight="1.0" 
     android:onClick="onClick" 
     android:clickable="true"/> 

    <ImageButton 
     android:id="@+id/mailButton" 
     android:layout_width="0.0dip" 
     android:layout_height="fill_parent" 
     android:background="@drawable/mailtab" 
     android:layout_weight="1.0" 
     android:onClick="onClick" 
     android:clickable="true"/> 

    <ImageButton 
     android:id="@+id/gethelpButton" 
     android:layout_width="0.0dip" 
     android:layout_height="fill_parent" 
     android:background="@drawable/gethelptab" 
     android:layout_weight="1.0" 
     android:onClick="onClick" 
     android:clickable="true"/> 

    <ImageButton 
     android:id="@+id/moreButton" 
     android:layout_width="0.0dip" 
     android:layout_height="fill_parent" 
     android:background="@drawable/moretab" 
     android:layout_weight="1.0" 
     android:onClick="onClick" 
     android:clickable="true"/> 

</LinearLayout></LinearLayout> 

enter image description here

ответ

1
setContentView(R.layout.help); 

с этим утверждением, вы устанавливаете help.xml, как макет будет показан. Позже вы надуваете еще один макет, делаете что-то с его изображением, но, насколько я вижу, этот макет не является частью help.xml, и он не установлен для отображения через setContentView.

попробовать это:

ImageView pdfImage; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 


    LayoutInflater inflater = (LayoutInflater) context.getSystemService 
     (Context.LAYOUT_INFLATER_SERVICE); 
    LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.listlayout, null); 
    pdfImage = (ImageView)ll.findViewById(R.id.pdfImage); 

    pdfImage.setBackgroundResource(R.drawable.pdflogo); 
    setContentView(ll); 
+0

Если я устанавливаю contentView в макет, то мой первоначальный макет не показывается. Это 'listlayout' только для моих строк в моей таблице. см. рисунок – BigT

+0

, пожалуйста, предоставьте структуру help.xml –

+0

Я добавил структуру xml – BigT

Смежные вопросы