<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF9E3E"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:text="用户注册"
android:textColor="#000000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:text="用户登录"
android:textColor="#000000"
/>
</RelativeLayout>我想实现“用户注册”离屏幕左边20dip的距离,而“用户登录”离屏幕右边20dip的距离,现在不知怎么“用户登录”跑到屏幕左边顶头来了,注:现在只能用RelativeLayout
解决方案 »
- Android 播放MP3 报错
- android:layout_marginBottom使用方法
- android sdk 的问题
- 使用Rexsee实现移动应用中缓存加速和预加载、JS注入、页面过渡动画
- 三星盖世s5660 求助!
- achartengine 怎么设置区间背景色
- android物理9键盘实现字符切换?
- android开发 大神帮我看看吧
- XMPP Error connecting (Network is unreachable)
- 从MainActivity中启动一个Service,为什么没有反应?
- android socket编程IP地址问题
- 请问adil提供的接口可以再封装成一个类吗
只能帮你顶了。。
是指该控件的右边与屏幕左边距的距离,而不是我先认为的控件的右边与屏幕右边距的距离那我如果想实现我想达到的效果,就得用android:layout_marginRight=屏幕的宽度-20dip
这个应该怎么写啊
RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on. Elements are rendered in the order given, so if the first element is centered in the screen, other elements aligning themselves to that element will be aligned relative to screen center. Also, because of this ordering, if using XML to specify this layout, the element that you will reference (in order to position other view objects) must be listed in the XML file before you refer to it from the other views via its reference ID.The example below shows an XML file and the resulting screen in the UI. Note that the attributes that refer to relative elements (e.g., layout_toLeft) refer to the ID using the syntax of a relative resource (@id/id).<?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="wrap_content"
android:background="@drawable/blue"
android:padding="10px" > <TextView android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:" /> <EditText android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label" />
<Button android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10px"
android:text="OK" /> <Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel" />
</RelativeLayout>Some of these properties are supported directly by the element, and some are supported by its LayoutParams member (subclass RelativeLayout for all the elements in this screen, because all elements are children of a RelativeLayout parent object). The defined RelativeLayout parameters are: width, height, below, alignTop, toLeft, padding[Bottom|Left|Right|Top], and margin[Bottom|Left|Right|Top]. Note that some of these parameters specifically support relative layout positions — their values must be the ID of the element to which you'd like this view laid relative. For example, assigning the parameter toLeft="my_button" to a TextView would place the TextView to the left of the View with the ID my_button (which must be written in the XML before the TextView).To view this sample code, see the Hello RelativeLayout tutorial.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:text="用户登录"
android:textColor="#000000"
android:layout_alignParentRight="true"
/>这个TV加入android:layout_alignParentRight="true",表示对于父类view右边齐.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF9E3E"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:text="用户注册"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:text="用户登录"
android:gravity="right"
/>
</RelativeLayout>
这样也可以
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF9E3E"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginLeft="右边距离默认到右边头"
android:text="用户注册"
android:textColor="#000000"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:layout_marginLeft="左边距离默认到左边头" android:text="用户登录"
android:textColor="#000000"
/>
</RelativeLayout>
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF9E3E"
>
<TextView
android:id="@+id/textview_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:text="用户注册"
android:textColor="#000000"
/>
<TextView
android:id="@+id/textview_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dip"
android:text="用户登录"
android:textColor="#000000"
/>
</RelativeLayout>