效果图:
Android——实现两个控件水平居中_第1张图片

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity">    <RelativeLayout        android:layout_marginTop="80sp"        android:layout_width="match_parent"        android:layout_height="wrap_content">        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_toLeftOf="@+id/center"            android:textSize="20dp"            android:text="左"/>        <View            android:id="@+id/center"            android:layout_width="3dp"            android:layout_height="40dp"            android:layout_centerInParent="true"            android:background="#ff0303"/>        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_toRightOf="@+id/center"            android:textSize="20dp"            android:text="右"/>    </RelativeLayout>    </LinearLayout>

android:layout_toRightOf 在该id控件的右方
android:layout_toLeftOf 在该id控件的左方

更多相关文章

  1. Android ListView控件基本用法
  2. Android的文本系列的控件
  3. android 控件属性大全
  4. 【Android】Android控件之Seekbar拖动条的使用
  5. android linearlayout 把控件view置底部(放在页面最下方)
  6. Android 之 自定义控件用法介绍
  7. Form表单组合控件

随机推荐

  1. 自媒体文章点击率一直这么低,还要坚持下去
  2. Ubuntu系统-FFmpeg安装及环境配置
  3. 重磅出击,Google Android经典资料!
  4. Android焦点问题
  5. 用 Python脚本生成 Android(安卓)SALT 扰
  6. Android(安卓)反编译资料整理
  7. Android源码下载出现的问题
  8. Android(安卓)五大布局
  9. Android核心模块
  10. android gradle 自动动态构建多平台的包