0

i'm working on this for hours and can't solve it. i want to merge 2 images in an XML file - so this will be the basic xml file for my shape. i want this shape to include a png which is the frame, and a png which is a picture inside a frame. that picture will change dynamically.

i've tried to use tag and to build my shape, but when i'm including it to my main xml file it fails because i can use merge only as root. try to did the same with , and still didn't get what i wanted...

what can i do to be able to merge these 2 pngs, and to be able to set the inner png position inside the frame png??

EDITED: some code:

<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>

this is my frame and inner pic xml source.. when looking at it inside the graphical layout it looks good. when including it in my main xml file, from somereason it flips the image... ???

this is part of my main 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>
Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154

2 Answers2

0

Have you considered using 9-patch and a custom layout? Here's an example.

Community
  • 1
  • 1
falro
  • 125
  • 6
0

Create a FrameLayout custom class. This class will have all the XML properties of a framelayout.

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);
    }

}

Your XML file would look something like

<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"/>

You can also create your own XML attributes for when you declare that in XML, so can directly declare the inner image in xml. If you need help with that you'll have to contact me or post another question.

Zaid Daghestani
  • 8,555
  • 3
  • 34
  • 44