【问题标题】:Trying to draw an arbitrary background image尝试绘制任意背景图像
【发布时间】:2015-12-10 12:31:54
【问题描述】:

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

<?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 图像,但它只是没有显示在屏幕上。

我错过了什么吗?

谢谢!

【问题讨论】:

  • 发布完整的布局文件
  • 更改您的相对布局 layout_height ="wrap_content"

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


【解决方案1】:

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

<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>

【讨论】:

    【解决方案2】:

    改变RelativeLayout的背景颜色

    android:background="#ffffff"
    

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

    【讨论】:

      猜你喜欢
      • 2013-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-31
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多