我是靠谱客的博主 动听母鸡,这篇文章主要介绍Android-使用绝对布局管理器固定组件的位置,现在分享给大家,希望可以做个参考。

使用绝对布局管理器

使用绝对布局管理器控制一个TextView组件和一个Button组件的绝对位置。

绝对布局管理器用表示,在使用该布局方式时,需要指定空间的x,y精确坐标
推荐使用XML布局文件中定义绝对布局管理器。

实现过程:
修改res/layout/main.xml文件,添加一个绝对布局管理器,然后分别添加一个TextView和一个Button组件,并分别通过android:layout_x和android:layout_y设置他们的绝对属性。

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <TextView 
        android:layout_x="20px"
        android:layout_y="10px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="用户名"
        android:hint="请输入用户名"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="18dp"
        android:layout_y="56dp"
        android:text="密码" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="70dp"
        android:layout_y="2dp"
        android:ems="10" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="70dp"
        android:layout_y="36dp"
        android:ems="10"
        android:inputType="textPassword" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="112dp"
        android:layout_y="116dp"
        android:text="确定" />

</AbsoluteLayout>

最后

以上就是动听母鸡最近收集整理的关于Android-使用绝对布局管理器固定组件的位置的全部内容,更多相关Android-使用绝对布局管理器固定组件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部