96SEO 2026-02-20 09:55 0
LinearLayout(线性布局)RelativeLayout(相对布局)TableLayout(表格布局)

FrameLayout(帧布局)AbsoluteLayout(绝对布局)GridLayout(网格布局)
2布局宽度android:layout_width布局高度android:layout_height
这两个属性一般放在一起写且必须设定里面的值可以任意进行调整可以是与父组件相同的match_parent也可以是适应自身大小的wrap_content还可以是各种数值如50dp100dp其中dp是一种屏幕密度的抽象单位。
wrap_content:适应自身大小android:layout_widthmatch_parent
android:layout_heightwrap_content
3外边距android:layout_margin内边距android:padding
外边距android:layout_margin整体距离android:layout_marginTop顶部距离android:layout_marginLeft
android:layout_marginStart左部距离android:layout_marginRight
android:layout_marginEnd右部距离android:layout_marginBottom底部距离
android:paddingTop顶部距离android:paddingLeft
android:paddingStart左部距离android:paddingRight
android:paddingEnd右部距离android:paddingBottom底部距离
标注左右的距离有两种表现形式以左为例一种是Left一种是Start这里主要是跟版本有关4.2以上用Start代替Left同理右部。
简单明了就是控件怎么布局它有两个属性水平的horizontal垂直的vertical。
垂直--LinearLayoutandroid:layout_widthmatch_parentandroid:layout_height400dpandroid:orientationverticalandroidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:backgroundcolor/blue/androidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:backgroundcolor/pink/androidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:background#00FF99/androidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:background#AA6699//LinearLayout
水平--LinearLayoutandroid:layout_widthmatch_parentandroid:layout_height400dpandroid:orientationhorizontalandroidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:backgroundcolor/blue/androidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:backgroundcolor/pink/androidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:background#00FF99/androidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:background#AA6699//LinearLayout
在一个布局中只能有一种排列方式要么垂直要么水平如果想多实现可以多用几个布局分模块的进行布局管理
对齐方式就是布局中的控件所在的位置我们现在主要的阅读方式为从左向右从上向下所以再添加控件时会自动的放于左上角切记第一条属性是写在大布局中的而不是单个的控件中以此段代码为例第二个可以放置在控件中调整位置在此处我们以第一种方式为例因为内容大同小异只是编写的位置不同罢了
LinearLayoutandroid:layout_widthmatch_parentandroid:layout_height400dpandroid:orientationverticalandroid:gravitycenterandroidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:backgroundcolor/blue/androidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:backgroundcolor/pink/androidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:background#00FF99/androidx.appcompat.widget.AppCompatButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:background#AA6699//LinearLayout
对齐方式andorid:gravitycenter整体居中andorid:gravityleft
andorid:gravitytop左部andorid:gravityright
andorid:gravityend右部andorid:gravitybottom底部andorid:gravitycenter_horizontal水平居中andorid:gravitycenter_vertical垂直居中
LinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontalandroid:background#e50c0cLinearLayoutandroid:layout_width0dpandroid:layout_heightfill_parentandroid:background#ffc0cbandroid:layout_weight1
/LinearLayoutandroid:layout_width0dpandroid:layout_heightfill_parentandroid:background#0000ffandroid:layout_weight1
权重andorid:layout_weight”“的值是可以随便定义的里面的数字相当于权重设置的数字相加为整个布局的大小比如以上代码为例第一个控件权重为1第二个也为1也就是说整个布局大小为2两个控件各占1数字可以任意更改控件也可以任意添加重要的是美观如下图
0dp的设置一般情况都是因为权重问题这样便可以按照自己所设置的比例进行显示水平布局设置width垂直布局设置height0dp。
前面提到了权重是占剩余部分的占据比例是因为我们在设计时不一定都是0dp有可能提前某个控件设置了长度或是高度这时如果我们再用权重属性分开的就是整个布局剩下没有占用的部分例如同样的代码我将第一个LinearLayout的宽度提前设置了200dp。
现在来看看效果
LinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontalandroid:background#e50c0cLinearLayoutandroid:layout_width200dpandroid:layout_heightfill_parentandroid:background#ffc0cbandroid:layout_weight1
/LinearLayoutandroid:layout_width0dpandroid:layout_heightfill_parentandroid:background#0000ffandroid:layout_weight2
1.在activity_main.xml文件中新建一个LinearLayout
LinearLayoutandroid:idid/abcandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontalandroid:background#e50c0c/LinearLayout
androidx.appcompat.app.AppCompatActivity;
{super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//
LinearLayout(MainActivity.this);//
的布局方向为垂直linearLayout.setOrientation(LinearLayout.VERTICAL);//
Button(MainActivity.this);button.setText(点击);//
对象并设置相应参数LinearLayout.LayoutParams
LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);layoutParams.weight
将布局参数应用到按钮上button.setLayoutParams(layoutParams);//
中linearLayout.addView(button);LinearLayout
添加到活动的根布局中rootLayout.addView(linearLayout);}
LinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationverticalandroid:layout_marginTop16dpandroid:layout_marginBottom16dp!--
--Viewandroid:layout_widthmatch_parentandroid:layout_height1dpandroid:background#000000
2第二种是使用LinearLayout的一个divider属性
xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:shaperectanglesolid
设置分割线的位置,none(无),beginning(开始),end(结束),middle(每两个组件间)
设置分割线的可以控制分隔线与子视图之间的间距使布局在显示分隔线时具有更灵活的外观效果主要用于
AdapterView如ListView、GridView中的分隔线样式
xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:idid/LinearLayout1android:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:dividerdrawable/ktv_line_divandroid:orientationverticalandroid:showDividersmiddleandroid:dividerPadding10dp
Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮1
/Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮2
在一个LinearLayout的水平方向中布置两个TextView,想让一个左,一个右,怎么搞?
xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontal
TextViewandroid:layout_widthwrap_contentandroid:layout_height200dpandroid:layout_gravityleftandroid:background#ffc0cbandroid:gravitycenterandroid:text~~~~~~~pink......
/TextViewandroid:layout_widthwrap_contentandroid:layout_height200dpandroid:layout_gravityrightandroid:background#0000ffandroid:gravitycenterandroid:text~~~~~~~blue......
xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontal
TextViewandroid:layout_widthwrap_contentandroid:layout_height200dpandroid:layout_gravityleftandroid:background#ffc0cbandroid:gravitycenterandroid:text~~~~~~~pink......
/TextViewandroid:layout_widthwrap_contentandroid:layout_height200dpandroid:layout_gravityrightandroid:background#0000ffandroid:gravitycenterandroid:text~~~~~~~blue......
xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:idid/LinearLayout1android:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontal
TextViewandroid:layout_width0dpandroid:layout_height200dpandroid:layout_weight1android:background#0000ffandroid:gravitycenterandroid:textO(∩_∩)O哈哈~
/Viewandroid:layout_width0dpandroid:layout_height0dpandroid:layout_weight1
/TextViewandroid:layout_width130dpandroid:layout_height200dpandroid:background#ffc0cbandroid:gravitycenterandroid:text(*^__^*)
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback