Android的XML - 覆盖文/中相对布局图像 [英] Android xml - overlaying text/images in a relative layout

查看:152
本文介绍了Android的XML - 覆盖文/中相对布局图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个背景的 ListActivity 每一行。我有我需要并排放置一侧的两个背景图像。有一个 leftshopitem 图像,作为该项目的图标的占位符,并在 rightshopitem 图像,这文本信息将被覆盖。

基本上我想以下属性:我需要的图像图标在 leftshopitem 图像为中心,我需要显示在<$ C $的textViews C> rightshopitem 图像。

目前,我有这个code - 这是我知道的是相当错误的。背景图像显示正确对齐,但是图标和文本都没有。我想我的问题是,我怎么能做出一个ImageView的父这样我就可以把相对其他对象到它的位置。

 &LT;的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / relativeLayout1
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT&GT;        &LT; ImageView的
            机器人:ID =@ + ID / leftbackground
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentLeft =真
            机器人:layout_alignParentTop =真
            机器人:SRC =@绘制/ leftshopitem/&GT;        &LT; ImageView的
            机器人:ID =@ + ID / IMG
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentLeft =真
            机器人:layout_alignParentTop =真
            机器人:layout_centerInParent =真
        /&GT;        &LT; ImageView的
        机器人:ID =@ + ID / rightbackground
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentTop =真
        机器人:layout_toRightOf =@ + ID / leftbackground
        机器人:SRC =@绘制/ rightshopitem/&GT;
    &LT;的LinearLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:方向=垂直
    机器人:paddingLeft =10dp
         &GT;
    &LT;的TextView
        机器人:ID =@ + ID /名称
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字颜色=#000000
       /&GT;    &LT;的TextView
        机器人:ID =@ + ID /重量
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字颜色=#000000
        机器人:TEXTSIZE =16SP
         /&GT;    &LT; / LinearLayout中&GT;&LT; / RelativeLayout的&GT;


解决方案

您可以使用 android_layout_toLeftOf =@ ID / leftbackground,android_layout_toRightOf =@ ID / leftbackground等来到它的位置,其他位置目标相关。

如果您改用的android:align_parentLeft =真正的等等,你可以根据你的需要把一个视图在另一个上面

您还可以使用 Android的设置图像作为底色(种MTHE同样的事情,做一个ImageView的一个父),在你的RelativeLayouts之一:背景=@绘制/ leftshopitem

I am trying to create a background for each row of a ListActivity. I have two background images that I need to place side by side. There is a leftshopitem image, which serves as a placeholder for the item icon, and the rightshopitem image, which the textual information is to be written over.

Basically I want the following properties: I need the image icon to be centered over the leftshopitem image, and I need the textViews to be displayed over the rightshopitem image.

At the moment, I have this code - which I realise is quite wrong. The background images show up correctly aligned, but the icon and text are not. I guess my question is, how can I make an imageView a 'parent' so that I can place other objects relative to it's position.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

        <ImageView
            android:id="@+id/leftbackground"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/leftshopitem" />

        <ImageView
            android:id="@+id/img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
        />

        <ImageView
        android:id="@+id/rightbackground"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/leftbackground"
        android:src="@drawable/rightshopitem" />


    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingLeft="10dp" 
         >
    <TextView
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#000000"
       />

    <TextView
        android:id="@+id/weight"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:textSize="16sp"
         />

    </LinearLayout>

</RelativeLayout>

解决方案

You can use android_layout_toLeftOf="@id/leftbackground", android_layout_toRightOf="@id/leftbackground" and so on to "place other objects relative to it's position".

If you instead use android:align_parentLeft="true" etc, you can put one view on top of another according to your needs.

You can also set the image as backround (kind of mthe same thing as "make an imageView a 'parent'") in one of your RelativeLayouts by using android:background="@drawable/leftshopitem".

这篇关于Android的XML - 覆盖文/中相对布局图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆