0

私はこれに何時間も取り組んでいますが、解決できません。XML ファイルで 2 つの画像を結合したいので、これが私の形状の基本的な xml ファイルになります。この形状に、フレームである png と、フレーム内の写真である png を含めたいと思います。その絵はダイナミックに変化します。

タグを使用してシェイプを構築しようとしましたが、メインの xml ファイルにタグを含めると、ルートとしてのみマージを使用できるため失敗します。で同じことをしようとしましたが、それでも私が望んでいたものが得られませんでした...

これらの 2 つの 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ファイルに含めると、何らかの理由で画像が反転します... ???

これは私のメイン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>
4

2 に答える 2

0

9 パッチとカスタム レイアウトの使用を検討しましたか? ここにがあります。

于 2012-05-23T16:08:41.553 に答える
0

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 で直接宣言できます。ヘルプが必要な場合は、私に連絡するか、別の質問を投稿する必要があります。

于 2012-05-23T16:10:02.883 に答える