2017-12-02 13 views
2

背景画像を画面いっぱいにするにはどうすればよいですか?私はいくつかの異なる提案を試みたが、何も動作していないようだ。以下はアプリの背景が画面に表示されない

enter image description here

私activity_main.xmlのためのコードです:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.andrewvanpeter.upandaway.MainActivity"> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:srcCompat="@drawable/background_flat_720x1280" /> 

</android.support.constraint.ConstraintLayout> 

答えて

1

まず解決策:

あなたはmatch_parentlayout_widthとあなたのImageViewlayout_heightを置くことができます。

<ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:srcCompat="@drawable/background_flat_720x1280" /> 

第二の溶液:あなたはConstraintLayoutに直接背景を設定することができます(とImageViewを削除することを忘れないでください)

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background_flat_720x1280" 
    tools:context="com.andrewvanpeter.upandaway.MainActivity"> 
+1

match_parentソリューションが機能しませんでした。多分私は別の何か間違っているよ。しかし、背景を直接設定しても効果はありました。どうもありがとうございました! – CheetahBongos

+0

問題ありません、それは喜びです!たぶんどこかに余白や余白があるかもしれません。あるいは、ImageViewに合わせる必要があります。 –

1

また、設定することができますこのようにXYに適合する画像ビューのscaletype:

<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scaleType="fitXY" 
    app:srcCompat="@drawable/background_flat_720x1280" /> 
+0

それは動作します。ありがとうございました – CheetahBongos

関連する問題