0

ImageView をフルスクリーン アプリの中央に配置しようとしているだけです。このサイトで、同じ質問のように思われるものを尋ねる投稿をいくつか読みました。読んだことはすべて試しましたが、中心に置くことができないようです。

これが私のレイアウト用のコードです。他のさまざまな投稿を試した結果、センタリングを取得するためにここにやり過ぎがある可能性があることに気付きました。このコードは、画面の左上部分に画像を配置します。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    android:id="@+id/RelativeLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:layout_gravity="center"
    android:background="#000000"
    android:orientation="vertical" >

    <ImageView
       android:id="@+id/image"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:layout_alignParentTop="false"
       android:layout_centerInParent="true"
       android:layout_gravity="center"
       android:layout_centerHorizontal="true"
       android:layout_centerVertical="true"
       android:adjustViewBounds="true"
       android:background="@android:color/black"
       android:contentDescription="@string/descImage"
       android:cropToPadding="false"
       android:gravity="center"
       android:src="@drawable/placeholder" />

AndroidManifest.xml のフルスクリーン コードを次に示します。

android:screenOrientation="landscape"
android:theme="@style/Theme.FullScreen">

Theme.FullScreen は次のように定義されます

<style name="Theme.FullScreen" parent="@android:style/Theme.Holo">
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowFullscreen">true</item>
</style>

ありがとう。

4

5 に答える 5

0

ImageView で scaleType="fitCenter" を使用します。

于 2014-05-22T20:18:41.460 に答える
0

サイズに使用するfill_parentと、親のサイズであるため、ビュー全体が親の中央に配置されません。

サイズを に変更するwrap_contentと、ビューのバウンディング ボックスが変更され、親の内側の中央に配置されます。

android:scaleTypeこのプロパティを使用してimageView、画像リソース自体をビュー内に配置する方法を指定することもできます。

デフォルトscaleTypeでは、境界ボックスが実際の画像自体よりも大きい場合、リソース画像が ImageView の左上隅に表示されます。

このandroid:adjustViewBoundsプロパティを使用して、OS が画像リソースに基づいて境界ボックスのサイズを自動的に変更するようにすることもできます。

于 2013-08-22T03:47:30.877 に答える