【问题标题】:Background Relative layout背景相对布局
【发布时间】:2014-02-27 21:18:35
【问题描述】:

我会设置我的活动背景。

这是我的布局(使用列表视图填充)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:background="#FFFFFF" >

    <TextView
        android:id="@+id/girone"
        style="@style/NomeSquadra"
        android:layout_width="fill_parent"
        android:layout_height="20dip" />

    <TextView
        android:id="@+id/home"
        style="@style/NomeSquadra"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/girone"
        android:layout_marginLeft="2dip"
        android:gravity="left|center_vertical" />

    <TextView
        android:id="@+id/away"
        style="@style/NomeSquadra"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/girone"
        android:layout_marginLeft="2dip"
        android:layout_toRightOf="@+id/vs"
        android:gravity="right|center_vertical" />

    <TextView
        android:id="@+id/vs"
        style="@style/NomeSquadra"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_below="@+id/girone"
        android:layout_centerHorizontal="true"
        android:background="#0000FF"
        android:gravity="center|center_vertical" />

</RelativeLayout>

如果我写 android:background="@drawable/logo"(到 relativeLayout),图像 logo.png 不是比例...我错在哪里?

【问题讨论】:

  • 问题不清楚,问你到底想要什么
  • 你可以在这里发布你想要的截图吗?
  • 尝试将颜色更改为更亮的颜色#ff0000,这样您就可以了解它实际占用了多少部分。
  • 上面布局中的listview在哪里,也看不到你使用logo.png作为背景。

标签: android android-relativelayout


【解决方案1】:

试试这个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/logo"
     >

【讨论】:

  • 上面布局中的列表视图在哪里。我只能看到文本视图
  • Arvind 是对的......你错过了父相对布局中的 android:layout_height="fill_parent" 属性。
【解决方案2】:

为这个布局的父级添加高度

 android:layout_height="fill_parent"

【讨论】:

  • android:background="@drawable/logo" 也设置了伙计
  • schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/ic_launcher" >
  • 我觉得那张照片有点问题,伙计
【解决方案3】:

android:layout_height 属性添加到RelativeLayout xml 如下...

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF" >

更新:

完美运行的 XML 布局...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/logo" >

    <TextView
        android:id="@+id/girone"
        style="@style/NomeSquadra"
        android:layout_width="fill_parent"
        android:layout_height="20dip" />

    <TextView
        android:id="@+id/home"
        style="@style/NomeSquadra"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/girone"
        android:layout_marginLeft="2dip"
        android:gravity="left|center_vertical" />

    <TextView
        android:id="@+id/away"
        style="@style/NomeSquadra"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/girone"
        android:layout_marginLeft="2dip"
        android:layout_toRightOf="@+id/vs"
        android:gravity="right|center_vertical" />

    <TextView
        android:id="@+id/vs"
        style="@style/NomeSquadra"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_below="@+id/girone"
        android:layout_centerHorizontal="true"
        android:background="#0000FF"
        android:gravity="center|center_vertical" />

</RelativeLayout>

【讨论】:

  • 可以添加当前布局输出问题的图片吗?
  • 如上更新 xml 并清理并构建您的项目...然后再次运行它。
  • 我的列表视图i.stack.imgur.com/4SxXn.png我的背景i.stack.imgur.com/heg3c.png我会合并两者
  • 在我的情况下......它工作得很好。我给你你的 xml 对我有用。
  • 如果我删除布局内的文本视图,工作正常。如果我添加 textview(足球结果列表)不起作用....
猜你喜欢
  • 1970-01-01
  • 2013-07-06
  • 2020-01-21
  • 2011-08-28
  • 2011-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多