试图绘制任意背景图像

时间:2015-12-10 12:31:54

标签: android android-layout android-studio android-imageview

我已经看过很多教程试图将图像作为我主要活动的背景。测试了很多方法,现在我用这个:

<?xml version="1.0" encoding="utf-8"?>


<merge
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/library"
        android:scaleType = "centerCrop"
        android:contentDescription="@string/bckgrndimg" />

<RelativeLayout 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:background="#ffffff"
    android:orientation="vertical"
    >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="370dp"
        android:layout_marginLeft="0dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true">
    </ListView>

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nuevo_libro"
        android:id="@+id/nuevoLibro"
        android:layout_above="@android:id/list"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="42dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/biblioteca_virtual"
        android:id="@+id/textView2"
        android:layout_above="@+id/nuevoLibro"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="31dp" />



</RelativeLayout>
</merge>

好的,这应该没问题,不应该吗?我的“图书馆”图像是一张900x600的PNG图像,但它不会出现在屏幕上。

我错过了什么吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

您需要图像视图吗? 你可以这样做:

<RelativeLayout 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:background="@drawable/library.."
    ...
>
...
</RelativeLayout>

答案 1 :(得分:0)

更改RelativeLayout的背景颜色

android:background="#ffffff"

android:background="@android:color/transparent"