8

画像を相対レイアウトの上に揃えようとしています。その後、画像を水平方向に中央に配置します。私が使用しているコードは次のとおりです。

<ImageView  
        android:id="@+id/collection_image_background"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"  />

、しかし、このコードは機能していません。画像は中央に配置されていますが、相対レイアウトの上部に配置されていません。で試してみましandroid:scaleType="fitStart"たが、実際には親の左と上にimagを揃えています。

必要に応じて画像を正しく配置する方法はありますか?

PS画像を次のように設定していることを忘れていますImageView

    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inTempStorage = new byte[8*1024];

    ops = BitmapFactory.decodeStream(cis,null,o2);
    ImageView view = (ImageView) findViewById(R.id.collection_image_background);
    view.setImageBitmap(ops);
4

1 に答える 1

19

コードは、割り当てたコンテンツ領域fill_parentが全体ビューを取り、中央に表示されることを除いて完璧に見えるので、次のように変更するだけですwrap_content

  <ImageView  
            android:id="@+id/collection_image_background"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"  />
于 2012-04-18T12:43:20.143 に答える