2012-05-23 90 views
0

我正在爲此工作數小時,無法解決它。 我想合併一個XML文件中的2個圖像 - 所以這將是我的形狀的基本xml文件。 我想要這個形狀包括一個PNG,這是一個框架,而一個PNG是一個框架內的圖片。該圖片將動態變化。android合併2張圖片

我試過使用標籤並構建我的形狀,但是當我將它包含到我的主要xml文件時,它失敗了,因爲我只能以root身份使用合併。 試圖做到這一點,並仍然沒有得到我想要的...

我能做些什麼來合併這兩個PNG,並能夠設置框架內部的PNG位置PNG?

編輯: 一些代碼:

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"    
    android:src="@drawable/userprofilepicture" 
    android:scaleType="fitXY" 
    android:contentDescription="@string/SmallLogo" /> 


<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:contentDescription="@string/SmallLogo" 
    android:scaleType="fitXY" 
    android:padding="30dp" 
    android:src="@drawable/questionmark" /> 

</FrameLayout> 

這是我的框架和內部PIC XML源.. 它的圖形佈局,看起來不錯裏面看時。 當它包含在我的主要XML文件,從somereason它翻轉圖像...?

這是我的主要XML的一部分:

 <TableRow> 

     <ImageView 
      android:layout_gravity="center_vertical" 
      android:layout_marginTop="2.5dp" 
      android:contentDescription="@string/SmallLogo" 
      android:src="@drawable/logosmall" /> 

     <ImageView 
      android:layout_gravity="center_vertical" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="2.5dp" 
      android:contentDescription="@string/slogen" 
      android:src="@drawable/slogen" /> 

     <include layout="@drawable/userprofilepicture" 
      android:layout_width="30dp" 
      android:layout_height="30dp"/> 

    </TableRow> 

回答

0

創建一個FrameLayout自定義類。該類將具有framelayout的所有XML屬性。

com.package.example; 

public class PictureFrame extends FrameLayout { 

    public PictureFrame(Context c, AttributeSet attrs) { 
     super(c, attrs); 
     LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     //This adds the image views as you've styled them in the XML file 
     inflater.inflate(R.layout.myFrameImages, this); 
    } 

    public void setInnerImage(int resource) { 
     ImageView ivInner = (ImageView) findViewById(R.id.innerImage); 
     ivInner.setImageResource(resource); 
    } 

} 

你的XML文件看起來像

<ImageView 
    android:src="@drawable/myFrameImage" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:scaleType="fitXY"/> 
<ImageView 
    android:src="@drawable/myInnerImage" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:scaleType="fitXY" 
    android:layout_margin="10dp" 
    android:id="@+id/innerImage"/> 

您還可以創建在聲明在XML爲自己的XML屬性,因此可以直接在XML聲明內的圖像。如果您需要幫助,您必須聯繫我或發佈其他問題。

+0

我已經將我的代碼添加到我的問題..請看看如果可能 –

+0

好吧,當我不包括,只是複製粘貼framelayout我的main.xml中它的好,謝謝! –

相關問題