android:gravity 和android:layout_gravity的区别 android:padding和android:layout_margin的区别...

理解Android布局属性:gravity与layout_gravity的区别
本文深入探讨Android布局管理器中的gravity与layout_gravity属性的区别,通过实例展示它们如何影响子控件在父控件中的位置。同时,文章还对比了padding与layout_margin在控件边界与间距上的作用。

一,android:gravity 和android:layout_gravity的区别

android;gravity是自己的内容相对于自己的控件的位置,而android:layout_gravity是自己相对于父类的位置。

举例,现在有个EditText,里面的文本时one,设置android:gravity="center"来让EditText中的文字在EditText组件中居中显示;同时我们设置EditText的android:layout_gravity="right"来让EditText组件在LinearLayout中居中显示。如下图示:

二,android:padding和android:layout_margin的区别

padding是站在父view的角度描述问题,它规定它里面的内容必须与这个父view边界的距离。margin则是站在自己的角度描述问题,规定自己和其他(上下左右)的view之间的距离,如果同一级只有一个view,那么它的效果基本上就和padding一样了


那接下来几个界面也像这样修改成这种形式,只用最小量修改。首先是fragment_home.xml:<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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=".ui.home.HomeFragment" android:fitsSystemWindows="true" android:background="@color/surface_background"> <!-- 🔍 输入框 --> <EditText android:id="@+id/home_input" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="请输入需要查询的公交线路或站点" android:textColorHint="#777777" android:textColor="@color/black" android:background="@drawable/rounded_edittext" android:minHeight="48dp" android:textSize="16sp" android:padding="12dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@id/home_search" app:layout_constraintHorizontal_chainStyle="packed" android:layout_marginStart="16dp" android:layout_marginEnd="8dp" android:layout_marginTop="88dp" /> <!-- 🔎 搜索按钮 --> <Button android:id="@+id/home_search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="搜索" app:layout_constraintTop_toTopOf="@id/home_input" app:layout_constraintBottom_toBottomOf="@id/home_input" app:layout_constraintStart_toEndOf="@id/home_input" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="16dp" /> <!-- 🚌 图片:居中偏上 --> <ImageView android:id="@+id/image_bus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitCenter" android:src="@drawable/bus" app:layout_constraintTop_toBottomOf="@id/home_input" app:layout_constraintBottom_toTopOf="@+id/text_home" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="144dp" android:layout_marginBottom="144dp"/> <!-- ℹ️ 底部说明文字 --> <TextView android:id="@+id/text_home" android:textColor="#777777" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:textAlignment="center" android:textSize="11sp" app:layout_constraintTop_toBottomOf="@id/image_bus" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> 其次是fragment_map.xml:<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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=".ui.map.MapFragment" android:fitsSystemWindows="true" android:background="@color/surface_background"> <androidx.constraintlayout.widget.Guideline android:id="@+id/guideline_top_offset" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent="0.015" /> <!-- 🔹 起点输入框 --> <EditText android:id="@+id/map_input1" android:layout_width="0dp" android:layout_height="48dp" android:hint="请输入起点" android:textColorHint="#777777" android:textColor="@color/black" android:background="@drawable/rounded_edittext" android:padding="12dp" android:layout_marginStart="16dp" android:layout_marginEnd="8dp" android:layout_marginTop="32dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@id/guideline_search" app:layout_constraintTop_toTopOf="@id/guideline_top_offset" /> <!-- 🔹 终点输入框 --> <EditText android:id="@+id/map_input2" android:layout_width="0dp" android:layout_height="48dp" android:hint="请输入终点" android:textColorHint="#777777" android:textColor="@color/black" android:background="@drawable/rounded_edittext" android:padding="12dp" android:layout_marginStart="16dp" android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@id/guideline_search" app:layout_constraintTop_toBottomOf="@id/map_input1" /> <!-- ✅ 分割线:75% 处(原样保留) --> <androidx.constraintlayout.widget.Guideline android:id="@+id/guideline_search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" app:layout_constraintGuide_percent="0.75" /> <!-- 🔍 搜索按钮:纵向拉高,覆盖两个输入框 --> <Button android:id="@+id/map_search" android:layout_width="0dp" android:layout_height="0dp" android:text="搜索" android:textSize="16sp" android:gravity="center" app:layout_constraintStart_toStartOf="@id/guideline_search" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@id/map_input1" app:layout_constraintBottom_toBottomOf="@id/map_input2" android:layout_marginEnd="16dp" /> <!-- 🗺️ 地图视图:从终点输入框下方开始,延伸到底部 --> <com.amap.api.maps.MapView android:id="@+id/map_view" android:text="Bus-1.0" android:textColor="#777777" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/map_input2" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginTop="4dp" android:layout_marginBottom="0dp"/> </androidx.constraintlayout.widget.ConstraintLayout> 接着是fragment_settings.xml:<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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=".ui.settings.SettingsFragment" android:fitsSystemWindows="true" android:background="@color/surface_background"> <!-- 🔹 Material Design 按钮组 --> <Button android:id="@+id/btn_gps" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="权限设置" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" android:layout_marginTop="56dp" /> <Button android:id="@+id/btn_apps" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="关于公交查询系统" app:layout_constraintTop_toBottomOf="@id/btn_gps" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" android:layout_marginTop="16dp" /> <Button android:id="@+id/btn_user" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="用户调研" app:layout_constraintTop_toBottomOf="@id/btn_apps" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" android:layout_marginTop="16dp" /> <Button android:id="@+id/btn_exit" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="退出程序" app:layout_constraintTop_toBottomOf="@id/btn_user" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" android:layout_marginTop="16dp" /> <!-- 🔹 图片:放在按钮下方 --> <ImageView android:id="@+id/image_bus" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="64dp" android:layout_marginBottom="64dp" android:src="@drawable/bus" app:layout_constraintBottom_toTopOf="@+id/text_settings" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn_exit" /> <!-- 🔹 底部 TextView --> <TextView android:id="@+id/text_settings" android:text="Bus-1.0" android:textColor="#777777" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:textAlignment="center" android:textSize="11sp" app:layout_constraintTop_toBottomOf="@id/image_bus" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> 还有activity_survey.xml:<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" android:fitsSystemWindows="true" android:background="@color/surface_background"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <!-- 问题1:评分 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginBottom="32dp" android:text="🚌 用户体验调研" android:textColor="#777777" android:textSize="24sp" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1. 您对本应用的整体评分是?" android:textStyle="bold" android:textColor="#777777" android:layout_marginBottom="8dp" /> <RadioGroup android:id="@+id/radioGroupRating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp"> <RadioButton android:text="⭐ 1分 - 非常不满意" android:textColor="@color/black" android:id="@+id/rb1" android:layout_height="match_parent" android:layout_width="match_parent"/> <RadioButton android:text="⭐⭐ 2分 - 不满意" android:textColor="@color/black" android:id="@+id/rb2" android:layout_height="match_parent" android:layout_width="match_parent"/> <RadioButton android:text="⭐⭐⭐ 3分 - 一般" android:textColor="@color/black" android:id="@+id/rb3" android:layout_height="match_parent" android:layout_width="match_parent"/> <RadioButton android:text="⭐⭐⭐⭐ 4分 - 满意" android:textColor="@color/black" android:id="@+id/rb4" android:layout_height="match_parent" android:layout_width="match_parent"/> <RadioButton android:text="⭐⭐⭐⭐⭐ 5分 - 非常满意" android:textColor="@color/black" android:id="@+id/rb5" android:layout_height="match_parent" android:layout_width="match_parent"/> </RadioGroup> <!-- 问题2:满意度 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2. 您对以下哪些方面或功能感到满意?(可多选)" android:textColor="#777777" android:textStyle="bold" android:layout_marginBottom="8dp" /> <CheckBox android:id="@+id/cb_ui" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="界面美观易用" android:textColor="@color/black"/> <CheckBox android:id="@+id/cb_speed" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="加载速度快" android:textColor="@color/black"/> <CheckBox android:id="@+id/cb_information" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="查询信息准确" android:textColor="@color/black"/> <CheckBox android:id="@+id/cb_other" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="其他" android:textColor="@color/black"/> <!-- 问题3:建议 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3. 您有什么改进建议?" android:textColor="#777777" android:textStyle="bold" android:layout_marginTop="24dp" android:layout_marginBottom="8dp" /> <EditText android:id="@+id/et_suggestion" android:layout_width="match_parent" android:layout_height="120dp" android:gravity="top" android:hint="请输入您的建议..." android:textColorHint="#777777" android:textColor="@color/black" android:inputType="textMultiLine" android:minLines="3" /> <!-- 提交按钮 --> <Button android:id="@+id/btn_submit" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="提交反馈" android:textSize="18sp" android:layout_marginTop="32dp" style="?android:attr/buttonStyle" /> </LinearLayout> </ScrollView> activity_about.xml:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" android:padding="20dp" android:fitsSystemWindows="true" android:background="@color/surface_background"> <!-- 软件名称 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="公交查询系统" android:textSize="28sp" android:textStyle="bold" android:textColor="#000" android:layout_marginBottom="10dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bus" android:textSize="18sp" android:textColor="#555555" android:layout_marginBottom="80dp" /> <!-- 软件图片 --> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bus" android:layout_marginBottom="100dp"/> <!-- 版本信息 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="版本:1.0" android:textSize="16sp" android:textColor="#777777" android:layout_marginBottom="20dp" /> <!-- 开发信息 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开发团队:white luminous" android:textSize="16sp" android:textColor="#777777" android:layout_marginBottom="10dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="邮箱:support@busapp.cn" android:textColor="#777777" android:textSize="16sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hao" android:textSize="8sp" android:layout_marginTop="100dp" android:textColor="#EEE"/> </LinearLayout> 以及activity_route_plan.xml: <!-- res/layout/activity_route_plan.xml --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:fitsSystemWindows="true" android:background="@color/surface_background"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="正在规划公交路线..." android:textSize="16sp" android:gravity="center" android:padding="16dp" android:textColor="#555" /> <com.amap.api.maps.MapView android:id="@+id/map_view" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
最新发布
11-07
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <LinearLayout android:id="@+id/MainPage" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <RelativeLayout android:id="@+id/SerialContent" android:layout_width="match_parent" android:layout_height="60dp"> <TextView android:id="@+id/Serial" android:layout_width="160dp" android:layout_height="match_parent" android:background="@drawable/form_shape" android:gravity="center" android:text="串口号" /> <Spinner android:id="@+id/SerialName" android:layout_width="100dp" android:layout_height="80dp" android:gravity="center" android:spinnerMode="dropdown" android:layout_toRightOf="@+id/Serial"/> <Spinner android:id="@+id/BaudRate" android:layout_width="140dp" android:layout_height="80dp" android:layout_toRightOf="@id/SerialName" android:gravity="center" android:spinnerMode="dropdown" /> <Button android:id="@+id/OpenSerial" android:layout_width="120dp" android:layout_height="match_parent" android:layout_toRightOf="@id/BaudRate" android:text="打开串口" /> <Button android:id="@+id/QuitSoftware" android:layout_width="140dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:text="退出软件" /> </RelativeLayout> <FrameLayout android:id="@+id/previewContent" android:layout_width="604.7dp" android:layout_height="430dp" android:visibility="gone"> <androidx.camera.view.PreviewView android:id="@+id/preview" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout> <RelativeLayout android:id="@+id/handleContent" android:layout_width="match_parent" android:layout_height="430dp" android:visibility="visible"> <TextView android:id="@+id/handle" android:layout_width="160dp" android:layout_height="match_parent" android:background="@drawable/form_shape" android:gravity="center" android:text="手柄" /> <LinearLayout android:id="@+id/RightContent" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@+id/handle" android:orientation="vertical"> <RelativeLayout android:id="@+id/content1" android:layout_width="match_parent" android:layout_height="60dp" android:layout_toRightOf="@+id/handle"> <Button android:id="@+id/ChangeDial" android:layout_width="140dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:text="带拨号盘版" /> </RelativeLayout> <LinearLayout android:id="@+id/DialContent" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <EditText android:id="@+id/receivedDataView" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:drawable/editbox_background" android:focusable="false" android:focusableInTouchMode="false" android:cursorVisible="false" android:gravity="top|left" android:inputType="textMultiLine" android:padding="8dp" android:scrollbars="vertical" android:hint="等待数据..." android:textSize="14sp" /> <LinearLayout android:id="@+id/mianBoard" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical"> <LinearLayout android:id="@+id/control" android:layout_width="match_parent" android:layout_height="74dp" android:orientation="horizontal" android:visibility="visible"> <EditText android:id="@+id/commandInput" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:hint="输入指令" android:paddingLeft="10dp" android:inputType="text" android:maxLines="1" /> <Button android:id="@+id/sendButton" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:text="发送" /> <Button android:id="@+id/clearDataView" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:text="清空" /> </LinearLayout> <GridLayout android:id="@+id/keyBoard" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="4" android:columnCount="3" android:rowCount="4" android:visibility="visible"> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="1" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="2" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="3" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="4" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="5" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="6" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="7" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="8" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="9" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="*" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="0" /> <Button android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="#" /> </GridLayout> <GridLayout android:id="@+id/NoKeyBoard" android:layout_width="match_parent" android:layout_height="0dp" android:columnCount="6" android:rowCount="4" android:layout_weight="5" android:visibility="gone"> <TextView android:id="@+id/keyA" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="KEYA" android:gravity="center"/> <Button android:id="@+id/keyAStart" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1.2" android:layout_rowWeight="1" android:text="开灯" /> <Button android:id="@+id/keyAClose" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1.2" android:layout_rowWeight="1" android:text="关灯" /> <TextView android:id="@+id/keyB" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="KEYB" android:gravity="center"/> <Button android:id="@+id/keyBStart" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1.2" android:layout_rowWeight="1" android:text="开灯" /> <Button android:id="@+id/keyBClose" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1.2" android:layout_rowWeight="1" android:text="关灯" /> <TextView android:id="@+id/key1" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="KEY1" android:gravity="center"/> <Button android:id="@+id/key1Start" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="开灯" /> <Button android:id="@+id/key1Close" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="关灯" /> <TextView android:id="@+id/key2" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="KEY2" android:gravity="center"/> <Button android:id="@+id/key2Start" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="开灯" /> <Button android:id="@+id/key2Close" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="关灯" /> <TextView android:id="@+id/key3" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="KEY3" android:gravity="center"/> <Button android:id="@+id/key3Start" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="开灯" /> <Button android:id="@+id/key3Close" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="关灯" /> <TextView android:id="@+id/key4" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="KEY4" android:gravity="center"/> <Button android:id="@+id/key4Start" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="开灯" /> <Button android:id="@+id/key4Close" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="关灯" /> <TextView android:id="@+id/key5" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="KEY5" android:gravity="center"/> <Button android:id="@+id/key5Start" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="开灯" /> <Button android:id="@+id/key5Close" android:layout_width="0dp" android:layout_height="0dp" android:layout_columnWeight="1" android:layout_rowWeight="1" android:text="关灯" /> </GridLayout> </LinearLayout> </LinearLayout> </LinearLayout> </RelativeLayout> <RelativeLayout android:id="@+id/VoiceContent" android:layout_width="match_parent" android:layout_height="80dp"> <TextView android:id="@+id/voice" android:layout_width="160dp" android:layout_height="match_parent" android:background="@drawable/form_shape" android:gravity="center" android:text="录音" /> <Button android:id="@+id/RecordingVoice" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_toRightOf="@+id/voice" android:text="开始录音" /> <TextView android:id="@+id/ShowVoiceData" android:layout_width="150dp" android:layout_height="match_parent" android:layout_toRightOf="@+id/RecordingVoice" android:background="@drawable/solid_shape" android:gravity="center" android:ellipsize="end" android:singleLine="false" android:maxLines="3"/> <Button android:id="@+id/PlayVoice" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_toRightOf="@id/ShowVoiceData" android:text="播放语音" /> <Button android:id="@+id/DeleteAudioAndView" android:layout_width="150dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_margin="2dp" android:text="删除" /> </RelativeLayout> <RelativeLayout android:id="@+id/CameraContent" android:layout_width="match_parent" android:layout_height="80dp"> <TextView android:id="@+id/camera" android:layout_width="160dp" android:layout_height="match_parent" android:background="@drawable/form_shape" android:gravity="center" android:text="摄像头" /> <Button android:id="@+id/OpenAndCloseCamera" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_toRightOf="@+id/camera" android:text="打开摄像头" /> <Button android:id="@+id/photograph" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_toRightOf="@id/OpenAndCloseCamera" android:text="拍照" /> <TextView android:id="@+id/PhotographData" android:layout_width="150dp" android:layout_height="match_parent" android:layout_toRightOf="@+id/photograph" android:background="@drawable/solid_shape" android:gravity="center" android:ellipsize="end" android:singleLine="false" android:maxLines="3"/> <Button android:id="@+id/RecordingView" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_toRightOf="@+id/PhotographData" android:text="录制视频" /> <TextView android:id="@+id/RecordingViewData" android:layout_width="150dp" android:layout_height="match_parent" android:layout_toRightOf="@+id/RecordingView" android:background="@drawable/solid_shape" android:gravity="center" android:ellipsize="end" android:singleLine="false" android:maxLines="3"/> <Button android:id="@+id/DeleteView" android:layout_width="150dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_margin="2dp" android:text="删除" /> </RelativeLayout> <LinearLayout android:id="@+id/ScreenTestContent" android:layout_width="match_parent" android:layout_height="80dp"> <TextView android:id="@+id/ScreenTest" android:layout_width="160dp" android:layout_height="match_parent" android:background="@drawable/form_shape" android:gravity="center" android:text="屏幕测试" /> <Button android:id="@+id/ScreenCheck" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:text="屏幕检测" /> <TextView android:id="@+id/TouchScreenCheck" android:layout_width="150dp" android:layout_height="match_parent" android:background="@drawable/form_shape" android:gravity="center" android:text="触摸屏检测" /> <Button android:id="@+id/ScribingTest" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:text="划线测试" /> <Button android:id="@+id/SinglePointTest" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:text="单点测试" /> </LinearLayout> <LinearLayout android:id="@+id/NetPortContent" android:layout_width="match_parent" android:layout_height="80dp"> <TextView android:id="@+id/NetPort" android:layout_width="160dp" android:layout_height="match_parent" android:background="@drawable/form_shape" android:gravity="center" android:text="网口" /> <TextView android:id="@+id/NetPortData" android:layout_width="150dp" android:layout_height="match_parent" android:ellipsize="end" android:layout_margin="2dp" android:gravity="center" android:background="@drawable/solid_shape"/> <TextView android:id="@+id/ping" android:layout_width="150dp" android:layout_height="match_parent" android:background="@drawable/form_shape" android:gravity="center" android:text="ping" /> <EditText android:id="@+id/pingInput" android:layout_width="150dp" android:layout_height="match_parent" android:hint="请输入" android:paddingLeft="10dp" android:text="192.168.1.1" android:layout_margin="2dp" android:inputType="text" android:maxLines="1"/> <Button android:id="@+id/pingSend" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:text="发送ping"/> <ScrollView android:id="@+id/scrollView" android:layout_width="200dp" android:layout_height="match_parent" android:fillViewport="true"> <TextView android:id="@+id/pingData" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/solid_shape" android:textSize="14sp" android:singleLine="false" android:maxLines="100" android:scrollbars="vertical" android:layout_margin="2dp"/> </ScrollView> <Button android:id="@+id/pingStop" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:text="停止"/> </LinearLayout> <RelativeLayout android:id="@+id/USBContent" android:layout_width="match_parent" android:layout_height="80dp"> <TextView android:id="@+id/USB" android:layout_width="160dp" android:layout_height="match_parent" android:background="@drawable/form_shape" android:gravity="center" android:text="USB接口" /> <TextView android:id="@+id/USBPath" android:layout_width="150dp" android:layout_height="match_parent" android:hint="未连接" android:ellipsize="end" android:layout_margin="2dp" android:gravity="center" android:background="@drawable/solid_shape" android:layout_toRightOf="@+id/USB"/> <Button android:id="@+id/getUSBPath" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:text="获取USB路径" android:layout_toRightOf="@+id/USBPath"/> <EditText android:id="@+id/WriteTextData" android:layout_width="150dp" android:layout_height="match_parent" android:inputType="text" android:paddingLeft="10dp" android:layout_toRightOf="@+id/getUSBPath"/> <Button android:id="@+id/WriteText" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:text="写入文本" android:layout_toRightOf="@+id/WriteTextData"/> <ScrollView android:id="@+id/scrollViewOpenTextData" android:layout_width="200dp" android:layout_height="match_parent" android:fillViewport="true" android:layout_toRightOf="@+id/WriteText"> <TextView android:id="@+id/OpenTextData" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/solid_shape" android:textSize="14sp" android:singleLine="false" android:maxLines="100" android:scrollbars="vertical" android:layout_margin="2dp" android:gravity="center"/> </ScrollView> <Button android:id="@+id/OpenText" android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="2dp" android:text="打开文本" android:layout_toRightOf="@+id/scrollViewOpenTextData"/> <Button android:id="@+id/DeleteText" android:layout_width="150dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_margin="2dp" android:text="删除" /> </RelativeLayout> </LinearLayout> </ScrollView>使以上代码实现自适应屏幕大小,给出全部完整的代码
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值