Android——实现两个控件水平居中
16lz
2021-12-04
效果图:
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控件的左方
更多相关文章
- Android之相对布局
- Android(安卓)ListView控件基本用法
- [Android]【安卓】开发小结
- android 布局详解
- Android中UI设计的一些技巧!!!
- Android中的五大布局
- Android抽屉实现
- Android的文本系列的控件
- android的图片添加、滚动条、单选框、多选框、跳转界面