布局文件-将项目定位到另一个项目的右侧(Android) [英] Layout File - Positioning Item to Right of Another Item (Android)

查看:86
本文介绍了布局文件-将项目定位到另一个项目的右侧(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将RelativeLayout中的一项放置在另一项的右侧.在下面的示例中,我希望将,"放置在描述字段的右侧.但是,问题在于它将逗号放在名称字段旁边的第一行.有人可以帮忙吗?

I'm trying to position one item in a RelativeLayout to the right of another. In the example below I want the "," to be placed to the right of the description field. However the problem is it puts the comma on the first line next to the name field. Can anyone help?

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="10sp">
    <TextView 
        android:id="@+id/name"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/name" />
    <TextView
        android:id="@+id/descriptioncomma"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=", "
        android:layout_toRightOf="@id/description" />

推荐答案

尝试以下代码,它应该可以工作: 按钮使用的layout_toRightOf属性为Textview小部件的ID.

Try this code, it should work: Button used layout_toRightOf attribute with id of Textview widget.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="10sp">
    <TextView 
        android:id="@+id/name" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/description" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/name" />
    <TextView
        android:id="@+id/descriptioncomma" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=","
        android:layout_below="@id/name"
        android:layout_toRightOf="@id/description" />
</RelativeLayout>

在双方的TextView中,您都添加了文本,然后进行了检查.

In Both TextView you add text and than check it.

这篇关于布局文件-将项目定位到另一个项目的右侧(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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