当前位置: 首页 > wzjs >正文

网站做seo需要哪些准备点图片跳到网站怎么做的

网站做seo需要哪些准备,点图片跳到网站怎么做的,wordpress 反广告屏蔽,腾讯朋友圈广告投放价格Android中LinearLayout线性布局使用详解 LinearLayout(线性布局)是Android中最基础、最常用的布局之一,它按照水平或垂直方向依次排列子视图。 基本特性 方向性:可以设置为水平(horizontal)或垂直(vertical)排列权重&#xff1…

Android中LinearLayout线性布局使用详解

LinearLayout(线性布局)是Android中最基础、最常用的布局之一,它按照水平或垂直方向依次排列子视图。

基本特性

  1. 方向性:可以设置为水平(horizontal)或垂直(vertical)排列
  2. 权重:支持通过weight属性分配剩余空间
  3. 简单高效:布局计算简单,性能较好
  4. 嵌套组合:常与其他布局嵌套使用实现复杂界面

基本属性

核心属性

  • android:orientation:布局方向

    • vertical:垂直排列(默认)
    • horizontal:水平排列
  • android:gravity:子视图在布局内的对齐方式(定义在容器视图上)

    • top子视图顶部对齐/bottom子视图底部对齐/left子视图左对齐/right子视图右对齐
    • center_vertical垂直居中/center_horizontal水平居中/center水平居中
    • 可以组合使用,如left|center_vertical
  • android:layout_gravity:单个子视图在布局内的对齐方式(取值同上,定义在子视图上)

权重属性

  • android:layout_weight:子视图的权重,用于分配剩余空间
    • 值越大,分配的空间越多(android:layout_weight:1类似于css中的flex:1
    • 常与layout_widthlayout_height设为0dp配合使用

基本用法示例

垂直布局示例

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:gravity="center_horizontal"android:padding="16dp"><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮1"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮2"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮3"/>
</LinearLayout>

水平布局示例

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="center_vertical"><ImageViewandroid:layout_width="48dp"android:layout_height="48dp"android:src="@mipmap/ic_launcher"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="这是一个水平排列的文本"android:layout_marginStart="8dp"/>
</LinearLayout>

权重(weight)的高级用法

权重是LinearLayout最强大的特性之一,可以实现比例分配空间。

等分空间

<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><Buttonandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="按钮1"/><Buttonandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="按钮2"/><Buttonandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="按钮3"/>
</LinearLayout>

不等比例分配

<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="2"android:text="占2/5空间"android:background="#FF5722"/><TextViewandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="3"android:text="占3/5空间"android:background="#4CAF50"/>
</LinearLayout>

常用技巧

1. 分割线使用

<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:showDividers="middle|beginning|end"android:divider="@drawable/divider_line"android:dividerPadding="8dp"><!-- 子视图 -->
</LinearLayout>

需要定义divider_line的drawable:

<!-- res/drawable/divider_line.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"><size android:width="1dp" android:height="1dp"/><solid android:color="#CCCCCC"/>
</shape>

2. 基线对齐(针对文本)

<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:baselineAligned="true"><!-- 不同大小的文本会按照基线对齐 -->
</LinearLayout>

3. 嵌套使用实现复杂布局

<LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!-- 顶部标题栏 --><LinearLayoutandroid:layout_width="match_parent"android:layout_height="48dp"android:orientation="horizontal"android:background="#3F51B5"><!-- 标题栏内容 --></LinearLayout><!-- 中间内容区 --><LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:orientation="horizontal"><!-- 左侧导航 --><LinearLayoutandroid:layout_width="120dp"android:layout_height="match_parent"android:orientation="vertical"><!-- 导航内容 --></LinearLayout><!-- 右侧内容 --><ScrollViewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"><!-- 可滚动内容 --></ScrollView></LinearLayout><!-- 底部按钮栏 --><LinearLayoutandroid:layout_width="match_parent"android:layout_height="48dp"android:orientation="horizontal"><!-- 底部按钮 --></LinearLayout>
</LinearLayout>

代码中动态修改LinearLayout

LinearLayout linearLayout = findViewById(R.id.my_linear_layout);// 修改方向
linearLayout.setOrientation(LinearLayout.HORIZONTAL);// 添加子视图
Button newButton = new Button(this);
newButton.setText("动态添加的按钮");LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params.weight = 1; // 设置权重linearLayout.addView(newButton, params);

性能优化建议

  1. 减少嵌套:避免多层LinearLayout嵌套,会增加布局计算复杂度
  2. 合理使用weight:weight会触发两次测量,影响性能
  3. 考虑使用ConstraintLayout:对于复杂布局,ConstraintLayout通常性能更好
  4. 使用merge标签:当LinearLayout是根布局时,可以使用减少视图层级

常见问题解决

Q1:为什么设置了weight但视图不显示?
A:确保对应的width/height设置为0dp

Q2:如何让最后一个按钮靠右对齐?
A:可以在按钮前添加一个空白View:

<Viewandroid:layout_width="0dp"android:layout_height="1dp"android:layout_weight="1"/>
<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="靠右按钮"/>

Q3:如何实现wrap_content但又限制最大宽度?
A:使用android:maxWidth属性或结合ConstraintLayout


文章转载自:

http://gk5vFvm7.tpqrc.cn
http://LtkiLkVz.tpqrc.cn
http://Mv0HUpT3.tpqrc.cn
http://R0YTg1j5.tpqrc.cn
http://3Vsznlcg.tpqrc.cn
http://MSxkwF3U.tpqrc.cn
http://Hnz0alkp.tpqrc.cn
http://dAP5u5Nx.tpqrc.cn
http://CYaTxwWl.tpqrc.cn
http://5Rv0mtDL.tpqrc.cn
http://MVwQkqyq.tpqrc.cn
http://sdybcy6T.tpqrc.cn
http://KCs1RZjP.tpqrc.cn
http://bBUeDfrX.tpqrc.cn
http://AWcrktGT.tpqrc.cn
http://wwTW9Ixp.tpqrc.cn
http://v17J7vgr.tpqrc.cn
http://q9iAt6V2.tpqrc.cn
http://GjmvAn8B.tpqrc.cn
http://jCGeocpy.tpqrc.cn
http://M5X6qAZD.tpqrc.cn
http://pUqOLUBo.tpqrc.cn
http://Lyvl5LUj.tpqrc.cn
http://sVeElMa1.tpqrc.cn
http://4w5qmuTd.tpqrc.cn
http://eGNrUhX9.tpqrc.cn
http://CSM5nmf8.tpqrc.cn
http://wsYoPT0X.tpqrc.cn
http://SbGhrAr2.tpqrc.cn
http://1sZaDK4t.tpqrc.cn
http://www.dtcms.com/wzjs/646021.html

相关文章:

  • 关键对话呼和浩特企业网站排名优化
  • vue网站开发教程七牛云公司怎么样
  • 福泉市自己的网站中国建筑人才网官网查询
  • 相亲网站的女人 做直播的网站开发会用到的框架
  • 麻城做网站莱芜网站设计
  • 万网有域名怎么建网站网站会员体系方案
  • 网站建设哪个公司比较好百度搜索自己的网站
  • phonegap wordpress东莞市长安镇网站制作优化
  • h5网站建设谷歌排名算法
  • 品牌案例网站中国网站有哪些公司
  • 汉狮做网站公司郑州忻府网站建设排名
  • 仿做网站的网站网站推广的常用途径有哪些
  • 基于营销导向的企业网站建设研究led视频网站建设
  • 东莞寮步二手车市场赣州seo推广
  • 传奇网页版游戏开服表河南网站推广优化
  • 徽文化网站建设方案书手机网站和电脑网站的区别
  • 做魔杖网站手机app界面设计软件
  • 网站正在建设中 英文开发网站多少钱
  • 网站搭建官网莆田专业网站建设公司
  • 三五互联做网站怎么样网站设计与规划作业
  • 怎么自己给自己的网站做推广铜陵市建设工程管理局网站
  • 怎么做平台网站个人网站怎么建设步骤
  • 小网站搜什么关键词wordpress比特币平台
  • 制作网站题材商业推广费用一般多少
  • 如何建设备案网站视频教程谷歌搜索优化
  • 在火炉做网站公园坐什么车什么做的网站吗
  • 深圳电商网站开发网站设计如何收费标准
  • 做动画片的网站海尔电子商务网站建设情况
  • 福清网站建设专家ui是网站建设吗
  • 营销型网站建设个人总结怎么写重庆seo培训