6

背景画像を線形レイアウトで垂直方向と水平方向の両方に伸縮または拡大縮小する方法を教えてください。ただし、背景を設定しようとするたびに、画面に合わせて画像が引き伸ばされません。アスペクト比を維持することも気にしません。

現時点でテストxmlにあるものは次のとおりです。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/title"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background">
</LinearLayout>

プレビュー (およびゲーム) では次のように表示されます。

ここに画像の説明を入力

layout_height を fill_parent に変更すると、背景が繰り返し表示されます。

ここに画像の説明を入力 解決策は非常に基本的なものだと確信していますが、何らかの理由でそれがありません。どんな助けでもいただければ幸いです

ありがとう

4

3 に答える 3

6

レイアウトの background 属性に使用できる背景レイアウト オプションは不明ですが、ImageView を外側の FrameLayout の最初の要素として最大の幅と高さでいつでも配置できます。次に、レイアウトに追加したものはすべて、この画像の上に描画されます。もちろん、必要なスケールタイプをロードすることもできます。おそらくあなたが達成しようとしているもののためのfitXYなど。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView 
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:contentDescription="@string/backgroundDescription"
    android:scaleType="centerCrop">
</ImageView>   
...
于 2013-10-14T15:44:59.030 に答える
4

android:scaleTypeこれは、可能な値のいずれかを持つ重要なパラメーターです。

  • マトリックス
  • フィットXY
  • 適合開始
  • フィットセンター
  • フィットエンド
  • 中心
  • センタークロップ
  • センターインサイド

必要に応じて画像がトリミングされてもかまわない場合 (画像とは比率が異なる画面)、画像が変形したくない場合は、 をお勧めしcenterCropます。画像がトリミングされていないことが重要であり、画像が歪んでいる場合は気にしないでくださいfitXY

これが助けになり、物事が少し解決されることを願っています...

于 2014-08-27T07:23:38.337 に答える
0

centerCrop で scaleType を使用できます

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

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"
    android:src="@drawable/background" />

于 2014-09-27T12:23:46.693 に答える