【问题标题】:Position of objects in relativelayout相对布局中对象的位置
【发布时间】:2012-10-18 22:00:01
【问题描述】:

我是 Android 的初学者。我使用 Eclipse 来编写我的应用程序。当我创建一个 .xml 类并想设置按钮的特定位置时,我使用以下代码:

<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/fm"
    android:baselineAligned="false"
    android:gravity="end" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:scrollX="100dp"
    android:scrollY="30dp"
    android:text="@string/edad" />

</RelativeLayout>

...但什么也没发生。它将按钮设置在角落。我怎样才能让它出现在其他地方?

【问题讨论】:

标签: android position android-relativelayout android-scroll


【解决方案1】:

你需要使用

android:layout_marginRight
android:layout_marginLeft 
android:layout_marginTop
android:layout_marginBottom 

【讨论】:

    【解决方案2】:

    需要使用android:layout_below等定位参数。详情请见Relative Layout Guide

    【讨论】:

      【解决方案3】:

      您应该单击按钮并转到属性。这就是不同的定位设置所在的位置。 例如下面的:@+id/VIEW 然后设置 marin top :10dip。这会将您的按钮设置在 VIEW 下方 10 处。

      【讨论】:

        【解决方案4】:
        <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        
        android:layout_marginLeft="100dp"
        android:layout_marginTop="30dp"
        android:text="@string/edad" />
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-16
          • 2019-09-24
          • 1970-01-01
          • 1970-01-01
          • 2014-02-14
          • 1970-01-01
          相关资源
          最近更新 更多