2010-11-21 27 views
0

私のImageViewは奇妙な理由から、画面中央に画像を表示しています。ImageViewが常に正しく表示されない場合の対応

私は私のアプリで縦向きを強制し、ここで私のレイアウトのための私のXMLコードです:だから

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:gravity="center"> 

    <ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/image_view" 
    android:layout_weight="1.0"/> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/message" 
    android:gravity="center_horizontal" 
    android:padding="10dip"/> 

    <Button 
      android:layout_gravity="center_horizontal" 
    android:layout_width="fill_parent" 
    android:textStyle="bold" android:id="@+id/action_button" android:selectAllOnFocus="false" android:layout_height="100dip" android:text="Click here to preform actions"/> 
</LinearLayout> 

、ページが画面の幅、以下のテキストを拡張し、途中で画像として表示されるはずですそれとその下のボタン。しかし、何らかの理由で、画像は画面の中央左に小さな箱のサムネイルとして表示されます。

答えて

2

ここでトップボックスの中央に画像を配置したい場合は、android:gravity="center"を表示したくない場合は、実際にはをImageViewに設定するだけです。 「center」は、スケーリングを必要としない場合は正しい値です。あなたがそうした場合はcenterInsideが適切かもしれません。その場合は、ImageViewに何らかの種類の寸法または重量を定義する必要があります。 scaleType値の詳細については、the documentationを参照してください。

画像の高さをfill_parentに設定したくない場合、画像の下にテキストがないことを意味します。画像全体が親のテキスト全体を塗りつぶすため、LinearLayoutにはスペースがありません。 ImageViewの高さをwrap_contentまたは一定の高さ(たとえば100dip)に設定することをお勧めします。

関連する問題