私はヘッダー画像でアクティビティを作成しました。このヘッダーイメージは、最初に、scaleTypeがcenterCropに設定されているImageViewを使用して、アクティビティのレイアウトxmlで作成されます。これは、私が望むことを行い、画像を中央に置き、ポートレートモードで左右にクリップし、すべてを横長モードで表示します。ImageView scaleType 'centerCrop'とビットマップ描画可能な重力の和に相当します。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="30dp"
android:paddingBottom="6dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:background="#919EAC"
android:orientation="vertical" >
<ImageView
android:id="@+id/header_image"
android:layout_width="match_parent"
android:layout_height="120dp"
android:contentDescription="@string/header_description"
android:scaleType="centerCrop"
android:src="@drawable/header" />
.... <other views> ...
私は、データを表示するために、ヘッダー画像空間を使用できるように、背景描画可能で、これを交換したいのですが、それは別の活動に同じレイアウトを繰り返し、私が保存されます。背景属性:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#919EAC" />
</shape>
</item>
<item>
<bitmap
android:antialias="true"
android:gravity="top|center_horizontal"
android:src="@drawable/header" />
</item>
</layer-list>
この描画可能ではそうでないレイアウトが定義する有色背景を定義し、そのヘッダ画像を定義私はアンドロイドに参照することができ描画可能を作成した。このため
それ以外の場合は、ImageViewとしてレイアウトに含まれます。
しかし、今では画像が縮小されていますが、切り取ることができます。
私は、このような
android:gravity="top|clip_horizontal"
などの他の重力モードを試してみました。しかし、静止画表示とは異なる/スケールを表示するように思わAndroidのドキュメントを確認します。
バックグラウンドドロワブルの正しい定義は何でしょうか?
あなたの問題の解決策を見つけることができましたか?私は同じことで苦労しています。 – Marty
related http://stackoverflow.com/questions/5119366/set-size-of-layered-drawable – mathheadinclouds
「fill_vertical | clip_horizontal」はどうですか? –