为什么要使用ConstraintLayout?

2023-11-10

本文为博主原创文章,转载请注明出处:http://blog.csdn.net/jingsummer/article/details/78615360

源码地址:ConstraintLayoutDemo

相信大家对ConstraintLayout并不陌生,Android Studio升级2.2之后,默认生成的XML布局已经从原来的RelativeLayout替换为ConstraintLayout,并且goole在去年的I/O大会上重点推出介绍了这个控件,对于ConstraintLayout到目前为止已经推出了很多的使用方法和属性还是比较给力的,并且到目前为止Google还在继续丰富其API和功能,所以这对于开发者而言是一个大的福音!下面我们就来看看它到底高明在哪里!!!

说明:因为文章中会用到大部分的ConstraintLayout的名词,我们在文章中会使用CL缩写来代替,使用RL代替RelativeLayout。

要引入ConstraintLayout的使用,我们需要在gradle文件中添加

implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta3'

Relative positioning(相对位置)

循序渐进,我们从最基本的来,这是我使用ConstraintLayout写的一个布局效果:

这样的布局是我们平时很常见的效果,下面我们就看看使用ConstraintLayout时如何实现的:

<android.support.constraint.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="com.example.ljj.constraintlayoutdemo.demolist.RelativePositioningActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:title="相对位置"
        app:titleTextColor="@android:color/white" />

    <TextView
        android:id="@+id/text_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/fab_margin"
        android:layout_marginTop="@dimen/fab_margin"
        android:text="奚梦瑶维密秀摔倒道歉"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar" />

    <ImageView
        android:id="@+id/image"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_marginTop="10dp"
        android:scaleType="fitXY"
        android:src="@drawable/image"
        app:layout_constraintLeft_toLeftOf="@id/text_title"
        app:layout_constraintTop_toBottomOf="@+id/text_title" />
        
    <TextView
        android:id="@+id/text_content"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="@dimen/fab_margin"
        android:text="11月20日晚,一众国内外维密天使闪亮登场。但在表演环节中,奚梦瑶不慎出现意外跌倒在台上,意外发生后,奚梦瑶立刻整理了一下头发和身上的装饰,站起身来继续走T台,并且露出专业和自信的笑容,全场观众也为她拍手鼓励。"
        app:layout_constraintLeft_toRightOf="@+id/image"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/image" />


    <TextView
        android:id="@+id/text_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="时间:2小时前"
        app:layout_constraintLeft_toLeftOf="@id/image"
        app:layout_constraintTop_toBottomOf="@+id/image" />
</android.support.constraint.ConstraintLayout>

从上面代码中可以发现,我们可以看到一共四个控件元素,在text_title中有两个属性:

app:layout_constraintLeft_toLeftOf="parent"

不难理解,此属性的意思是text_title元素的左侧和父布局的左侧对齐,这是和父布局设置的相对依赖关系

app:layout_constraintTop_toBottomOf="@+id/toolbar"

此属性的意思是text_title的顶部在toolbar控件的下方,这是text_title设置的和toolbar位置上的依赖关系,如果我们希望控件A在控件B的下面,就可以这么写。

继续往下看text_content中还设置了

app:layout_constraintTop_toTopOf="@+id/image"

此属性的作用是使text_content和image空间顶部对齐,相当于RL中的alignTop。

这些属性的使用并不难理解,和RL中除了写法不同,理解起来都差不多,但是写的过程中,我发现了一些细节:
1、说明,如果直接设置marginLeft是不起作用的,需要和layout_constraintLeft_toLeftOf等对应的属性搭配使用
2、我们将text_content的 android:layout_width="0dp"设置为0dp,这就跟RL的写法不同了,稍后介绍这个属性,下面先看小CL提供的相对位置依赖的属性:其中大部分在上面的例子中已经涉及到了,也不难理解,大家可以自己试下。

layout_constraintLeft_toLeftOf
layout_constraintLeft_toRightOf
layout_constraintRight_toLeftOf
layout_constraintRight_toRightOf
layout_constraintTop_toTopOf
layout_constraintTop_toBottomOf
layout_constraintBottom_toTopOf
layout_constraintBottom_toBottomOf
layout_constraintBaseline_toBaselineOf
layout_constraintStart_toEndOf
layout_constraintStart_toStartOf
layout_constraintEnd_toStartOf
layout_constraintEnd_toEndOf

MATCH_CONSTRAINT

我们在上面留了一个问题,就是

android:layout_width="0dp"

将宽度设置为0dp在CL中意味着什么呢?
现将android:layout_width修改为wrap_content试试,效果如下:

可以看到text_content的内容已经脱离了之前的依赖,对于解决这种问题,我们就可以使用0dp的设置,那这个0dp又以为只什么呢?官方是这样介绍的:

Using 0dp, which is the equivalent of "MATCH_CONSTRAINT"
Important: MATCH_PARENT is not recommended for widgets contained in a ConstraintLayout. Similar behavior can be defined by using MATCH_CONSTRAINT with the corresponding left/right or top/bottom constraints being set to "parent".

也就是说在CL中MATCH_PARENT已经不存在了,对于这个属性值,我们就介绍到这里,至于为什么要这样改,我也不知道CL是怎么想的

Centering positioning And Bias (居中和偏移量)

上代码:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    ....
    ">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        ... />

    <Button
        android:id="@+id/button_center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/fab_margin"
        android:text="居中"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <Button
        android:id="@+id/button_bias"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/fab_margin"
        android:text="偏移量"
        app:layout_constraintHorizontal_bias="0.1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button_center" />
        
</android.support.constraint.ConstraintLayout>

对应实现效果:

先看居中的button_center 元素设置了两个属性:

app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"

设置这两个属性之后说明父布局的左右拉力对button是相等的,所以button居中,使用CL写XML时,左右居中使用上面两个属性,相对应的上下居中使用属性:

app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"

再看button_bias的属性中多了一个

app:layout_constraintHorizontal_bias="0.1"

此属性就是设置水平方向的偏移量,0.1表示左右侧距离比为1:9,此属性必须和居中属性一起显示才会起作用,相对应的还有

layout_constraintVertical_bias 

Circular positioning(圆形定位)

看到这个功能时我是激动的,瞬间觉得CL提升了一个档次,圆形定位的相关属性是在CL1.1版本新增的功能,个人感觉很好用,然后就路转粉了,哈哈,我先贴出一张图:

相信大家对这个类型的布局都不陌生,无论是项目中增加新功能,还是IM聊天中有新消息,都会有类似的需求,下面来瞅瞅CL是如何实现的

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    ...>
    
    <ImageView
        android:id="@+id/image"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/icon_circle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
	    android:id="@+id/image_point"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/red_point"
        app:layout_constraintCircle="@id/image"
        app:layout_constraintCircleAngle="35"
        app:layout_constraintCircleRadius="40dp" />
        
</android.support.constraint.ConstraintLayout>

从XML中可以看出image_point也就是上面的原点提示中有三个属性:

app:layout_constraintCircle="@id/image"   //表示以image为原点
app:layout_constraintCircleAngle="35"     //与数值角度为35的方向上布局此控件
app:layout_constraintCircleRadius="40dp"  //半径40

对这三个属性,官方给了一张图非常清楚的表达了这三个参数的含义:

提示:此属性是CL在1.1版本新增的,如果要使用,请把你的CL升级为1.1哦

Margins

对于margins,CL也提出了一些属性,如下:

android:layout_marginStart
android:layout_marginEnd
android:layout_marginLeft
android:layout_marginTop
android:layout_marginRight
android:layout_marginBottom

但是因为这些属性和RL中的意义和使用方式都相同,所以这里不做过多的介绍,重点介绍下我们之前没有的

layout_goneMarginStart
layout_goneMarginEnd
layout_goneMarginLeft
layout_goneMarginTop
layout_goneMarginRight
layout_goneMarginBottom

这几个属性和上面的不同之处在于前面多了一个gone,什么意思呢,上图来说话:

这是使用CL写的依赖布局:底部文字依赖于图片,在图片的下方,如果我将上面的图隐藏掉,会这样子

但是怎么办,我的需求是即使将图片隐藏掉,我底部的文字位置不变,这是这个新的属性就可以起作用了,在下面的文字上设置

app:layout_goneMarginTop="100dp" 

ok啦,你尽管去GONE,我才不怕:

注:当text的位置依赖的元素GONE之后,此属性才会起作用

ratio (宽高比)

关于设置ratio的属性如下:

app:layout_constraintDimensionRatio="2:1" 
app:layout_constraintDimensionRatio="H,2:1"
app:layout_constraintDimensionRatio="w,2:1"
<TextView
   android:layout_width="0dp"
   android:layout_height="0dp"
   android:background="@color/colorAccent"
   app:layout_constraintDimensionRatio="2:1"
   app:layout_constraintLeft_toLeftOf="parent"
   app:layout_constraintRight_toRightOf="parent"
   />

在XML中,设置了app:layout_constraintDimensionRatio="2:1"方法,对于这个控件来说,其宽高比为2:1,如图

我们在设置ratio时,将宽高都设置为match_constraint,就是0dp,并且添加了如下属性才会起作用:

app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"

除此之外,还有两个属性:

app:layout_constraintDimensionRatio="H,2:1"
app:layout_constraintDimensionRatio="w,2:1"

可以自己试一下,在水平和竖直方向设置时对应的不同效果。

Chains(链条)

今天很累,写到这里已经语无伦次的赶脚,快刀斩乱麻,直接上图:

看到官网介绍,将chains相关的属性和使用情况都试了一遍,大致就是这样纸滴,对这些形状分别介绍写法:

1、三个控件等分,类似于项目底部tab实现

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="乱花"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/button2" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="渐欲"
        app:layout_constraintLeft_toRightOf="@id/button1"
        app:layout_constraintRight_toLeftOf="@id/button3" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="迷人眼"
        app:layout_constraintLeft_toRightOf="@id/button2"
        app:layout_constraintRight_toRightOf="parent" />

为每个元素添加两两相互依赖,来实现等分功能,在这里我们还可以通过

app:layout_constraintHorizontal_weight

来控制每个元素的Item,这里的weight使用和LL中的使用方式一致,如果我将他们的weight设置分别为1,1,2,则效果为:

注:实现横向等分功能,必须设置宽度为0dp,并且两两互相依赖。

2、效果2,下面两张图是效果实现和官网上对这种效果的chains(链)作用力

可以看到A为head,在head元素中设置其chainStyle可以改变对链条之前的相互作用力,来实现不同效果

 <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin_top"
        android:text="浅草"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/button5"
        app:layout_constraintTop_toBottomOf="@id/button1" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="才能"
        app:layout_constraintLeft_toRightOf="@id/button4"
        app:layout_constraintRight_toLeftOf="@id/button6"
        app:layout_constraintTop_toTopOf="@id/button4"

        />

    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="没马蹄"
        app:layout_constraintLeft_toRightOf="@id/button5"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@id/button4" />

app:layout_constraintHorizontal_chainStyle="spread"
android:layout_width="wrap_content"

这两个属性组合实现上述效果,注,chainStyle的默认值是spread,如果不设置chainStyle的属性,则默认为spread

3、效果三

实现:

app:layout_constraintHorizontal_chainStyle="spread_inside"
android:layout_width="wrap_content"

4、效果四

实现:
app:layout_constraintHorizontal_chainStyle="packed"
android:layout_width="wrap_content"

除此之外,效果4还可以和我们上面介绍的Bias(偏移量一起使用),实现偏移效果。

总结:所以app:layout_constraintHorizontal_chainStyle有三个不同的取值,分别是spread、packed、spread_inside,不同的属性值和宽高值设置可以实现不同的效果,如上面介绍,如果还不是很清楚,稍后会附上源码。

guideLine(辅助线)

guideLine也是CL在1.1版本新增的功能,主要用于辅助布局,即类似为辅助线,横向的、纵向的。该布局是不会显示到界面上的。提供了三个属性:

layout_constraintGuide_begin
layout_constraintGuide_end
layout_constraintGuide_percent

先来看一下其实现

<android.support.constraint.ConstraintLayout 
...>
    <!--辅助线1 竖直辅助线,距离左侧100dp-->
    <android.support.constraint.Guideline
        android:id="@+id/guide_line"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="100dp"
        />
        
    <!--竖直线2 水平辅助线,距离上测150dp-->
    <android.support.constraint.Guideline
        android:id="@+id/guide_line1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="150dp" />
        
    <!--button1位置在两个辅助线的交点位置,通过两个辅助线来控制控件位置-->
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button1"
        app:layout_constraintBottom_toBottomOf="@id/guide_line1"
        app:layout_constraintStart_toStartOf="@id/guide_line" />

    <!--button2 上下居中,并且左侧依赖于guide_line的辅助线显示-->
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@id/guide_line"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

上面的XML代码中,我们添加了两个GuideLine辅助线,button1的位置在两个辅助线的交点处,button2左侧依赖于guide_line的辅助线显示并且上下居中显示,实现出来的效果如图:

在guideLine控件中,通过设置

android:orientation 

来区分是竖直还是水平辅助线

##总结
到这里,ConstraintLayout的属性大致介绍完成了,写上面的代码示例我们根本就没有使用嵌套布局,这也是ConstraintLayout的另一个比较牛的功能,减少了View层级的嵌套,降低了界面的渲染绘制层,下面总结下本文介绍到的所有的属性


###constraint 属性

  • layout_constraintLeft_toLeftOf
  • layout_constraintLeft_toRightOf
  • layout_constraintRight_toLeftOf
  • layout_constraintRight_toRightOf
  • layout_constraintTop_toTopOf
  • layout_constraintTop_toBottomOf
  • layout_constraintBottom_toTopOf
  • layout_constraintBottom_toBottomOf
  • layout_constraintBaseline_toBaselineOf
  • layout_constraintStart_toEndOf
  • layout_constraintStart_toStartOf
  • layout_constraintEnd_toStartOf
  • layout_constraintEnd_toEndOf

MATCH_CONSTRAINT

  • android:layout_width=“0dp”
  • android:layout_height=“0dp”

Bias偏移量设置

  • app:layout_constraintHorizontal_bias
  • app:layout_constraintVertical_bias

CircularPositioning 圆形定位

  • app:layout_constraintCircle
  • app:layout_constraintCircleRadius
  • app:layout_constraintCircleAngle

Margin

  • layout_goneMarginStart
  • layout_goneMarginEnd
  • layout_goneMarginLeft
  • layout_goneMarginTop
  • layout_goneMarginRight
  • layout_goneMarginBottom

Ratio

  • app:layout_constraintDimensionRatio=“2:1”
  • app:layout_constraintDimensionRatio=“H,2:1”
  • app:layout_constraintDimensionRatio=“w,2:1”

Chains(链条)

app:layout_constraintHorizontal_chainStyle
取值:spread、packed、spread_inside


GuideLine(辅助线)

  • layout_constraintGuide_begin
  • layout_constraintGuide_end
  • layout_constraintGuide_percent
  • android:orientation 通过这个属性来区分是竖直的还是水平的辅助线

最后,附上源码地址:https://github.com/gitjing/ConstraintLayoutDemo.git
本文会随着ConstraintLayout的功能增改不断更新,希望大家不吝赐教。
借鉴:ConstraintLayout官网API

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么要使用ConstraintLayout? 的相关文章

  • 如何使用 php DOM 获取 内的值?

    我如何使用 php DOM 获取 内的值 这是我的 xml 中的一些代码
  • Android:初始化本机 AudioRecord 对象时 AudioRecord 错误代码 -20

    Android 我想从麦克风读取缓冲区 以便我可以对其执行处理 以下是我的代码 int sampleRateInHz 8000 44100 22050 and 11025 int channelConfig AudioFormat CHAN
  • Android 中的 Fragment-Fragment 通信

    我在Android编程方面处于初级水平 所以我需要你真诚的帮助 请任何人帮助我 我正在尝试使用片段构建滑动用户界面 所以我真正的疑问是 我有一个Fragment say FragmentA 它有一个TextView and Button在其
  • Android 图表[关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在开发一个项目 其中有一些图表 图形 刻度图 烛台图和范围图 但问题是 没有该图表的库 我有烛台图的
  • 当满足条件时,如何以编程方式更改 ImageButton src 目标?

    我有一个学校项目 我正在尝试开发一个手电筒应用程序 对于开 关 ImageButton 我想要 4 个自定义图像 如果手电筒关闭 turn on png 默认 turn on pressing png 按下状态 true 如果手电筒打开 t
  • 当路径的点超出视野时,Android Canvas 不会绘制路径

    我在绘制路径时遇到了 Android Canvas 的一些问题 我的情况是 我有一个相对布局工作 如地图视图 不使用 google api 或类似的东西 我必须在该视图上绘制一条路径 canvas drawPath polyPath bor
  • 退出设备上的 system.img

    我正在为我们部署给客户的设备 LG p509 Optimus 1 开发自动应用程序更新解决方案 我们可以控制这些设备 并且目前在它们上安装自定义内核 但不是完整的自定义 ROM 由于我们试图在设备上自动更新我们的应用程序 因此我们需要由我们
  • Ionic 2 RC0 和 Angular 2 最新的 Android 构建错误(ngc:错误:静态解析符号值时遇到错误)

    当我使用构建android时出现错误ionic build android命令 ngc 错误 静态解析符号值时遇到错误 引用本地 非导出 符号 字典 考虑导出符号 原始 ts文件中的位置14 8 解析符号TRANSLATION PROVID
  • 从ListView中隐藏行而不占用空间

    我有一个带有关联 ArrayAdapter 的 ListView 它在多个活动中显示其内容 不幸的是 现在有必要 我的 ListView 在其中一项设置中不显示其所有元素 而仅显示 属性 未设置为 true 的元素 我想避免使用两个具有不同
  • ExpandableListview OnGroupClickListener 未触发

    我正在关注这个 以编程方式折叠 ExpandableListView 中的组 https stackoverflow com questions 4314777 programmatically collapse a group in ex
  • React Native Expo StackNavigator 重叠通知栏

    我正在尝试为我的 React Native Expo 应用程序实现导航栏 这里有一个问题 dependencies expo 18 0 3 react 16 0 0 alpha 12 react native 0 45 1 react na
  • Android 中 localTime 和 localDate 的替代类有哪些? [复制]

    这个问题在这里已经有答案了 我想使用从 android API 获得的长值 该值将日期返回为长值 表示为自纪元以来的毫秒数 我需要使用像 isBefore plusDays isAfter 这样的方法 Cursor managedCurso
  • Android蓝牙java.io.IOException:bt套接字已关闭,读取返回:-1

    我正在尝试编写一个代码 仅连接到运行 Android 5 0 KitKat 的设备上的 目前 唯一配对的设备 无论我尝试了多少方法 我仍然会收到此错误 这是我尝试过的最后一个代码 它似乎完成了我看到人们报告为成功的所有事情 有人能指出我做错
  • 控制 OverlayItem 大小

    我正在构建一个在单个 ItemizedOverlay 中包含几十个 OverlayItems 的地图 我的地图设计为可以非常近距离地查看 大约缩放级别 18 并且 OverlayItems 彼此非常接近 地图放大时看起来不错 但是 如果用户
  • 是否可以通过 Android 应用程序来录音?

    我是一名开发人员 希望创建一个 Android 应用程序来记录电话 这是出于我个人的需要 为了我自己的目的和记录而记录电话 是否有可能做到这一点 是否可以访问麦克风以及通过扬声器发出的声音 我对 Android 开发有点陌生 所以请耐心等待
  • 无法使用 findViewById() 找到视图

    我找不到TextView通过致电findViewById 即使 ID 确实存在 OtherActivity public class OtherActivity extends Activity Override protected voi
  • Android SearchView 在启动时隐藏键盘

    我有一个小问题正在尝试解决 当我打开应用程序时 键盘会显示输入搜索视图的查询 不过 我只想在单击搜索视图时显示键盘 我该如何解决 Thanks 这对我有用 用于隐藏焦点的代码 searchView SearchView view findV
  • 如何在android中通过蓝牙向配对设备发送短信?

    在我的应用程序中 我想通过蓝牙发送和接收短信 我可以在列表视图中看到配对设备名称和地址的列表 但是当我尝试向配对设备发送文本时 什么也没有发生 在其他设备中没有收到文本 这是我向配对设备发送消息的代码 private void sendDa
  • Android 标记如何实现拖放?

    你好 我正在 Android 中开发 MapView 应用程序 我有三个标记 我希望稍后能够使用 Google Map API getlocation function 为了尝试一下 我想使用拖放功能移动标记 然后检查位置 任何人都可以通过
  • 将对象从手机共享到 Android Wear

    我创建了一个应用程序 在此应用程序中 您拥有包含 2 个字符串 姓名和年龄 和一个位图 头像 的对象 所有内容都保存到 sqlite 数据库中 现在我希望可以在我的智能手表上访问这些对象 所以我想实现的是你可以去启动 启动应用程序并向左和向

随机推荐

  • 归并排序的思想

    归并排序是一种基于分治思想的经典排序算法 它将待排序的数组分成两个部分 然后递归地对这两个部分进行排序 最后再将排序好的两个部分归并成一个有序的数组 具体实现过程如下 1 将待排序数组不断二分 直到只剩下一个元素 此时该元素就是有序的 2
  • C语言基础(十二)- 数据结构概览

    相关术语 数据 类 数据对象 集合 数据元素 类对象 数据项 属性 什么是数据结构 概念 相互之间存在一种或多种特定关系的数据元素 类对象 的集合 数据结构包括 数据的逻辑结构 数学形式 集合结构 线性结构 1 1 树形结构 1 n 图形结
  • ORA-28009:connection as SYS should be as SYSDBA OR SYSOPER

    1 美图 1 背景 Navicate链接ORACLE报错 ORA 28009 connection as SYS should be as SYSDBA OR SYSOPER 直接链接报错 ORA 28009 connection as S
  • elasticsearch启动报错解决 问题集分析

    elasticsearch解决启动报错问题集 ps 别问我为什么知道这么多报错 我就是从安装到启动 一步一步按着下面报错顺序踩坑的 气死了 希望能帮到入门的你 1 内存报错 报错信息 Java HotSpot TM 64 Bit Serve
  • Hadoop实战实例

    分享一下我老师大神的人工智能教程 零基础 通俗易懂 http blog csdn net jiangjunshow 也欢迎大家转载本篇文章 分享知识 造福人民 实现我们中华民族伟大复兴 Hadoop实战实例 Hadoop是Google Ma
  • Numpy.linalg模块的lstsq()进行线性回归拟合(数学建模)

    建模中经常使用线性最小二乘法 实际上就是求超定线性方程组 未知数少 方程个数多 的最小二乘解 前面已经使用pinv 求超定线性方程组的最小二乘解 下面再举两个求最小二乘解的例子 并使用numpy linalg模块的lstsq 函数 求解 先
  • cef3:禁止win10高dpi下cef对内部网页进行缩放

    cef对内部网页进行缩放
  • Pycharm中常用快捷键使用及注释方式

    Pycharm中常用快捷键使用及注释方式 1 快捷键 设置 Ctrl Alt s 或 File gt Settings gt Keymap gt 搜索栏搜索 format gt Code 快速创建文件 Alt Insert 快速注释代码 C
  • insightface pytorch 答疑指南

    之前写过一篇人脸识别从原理到实践 详细介绍了人脸识别相关的算法 模型和Loss等 里面也提到insightface成为当前工业事实上的基准 但是它各种牛逼 唯一不足的点就是开始时选了mxnet框架开发 奈何现在基本没什么人用了 所以在22年
  • PCL 使用LCCP算法进行点云分割

    LCCP分割 一 算法原理 1 概述 2 参考文献 二 代码实现 三 结果展示 1 原始点云 2 分割结果 四 相关链接 五 测试数据 一 算法原理 1 概述 LCCP是Locally Convex Connected Patches的缩写
  • Android使用Gradle统一配置依赖版本

    转自 http blog csdn net u014651216 article details 54602354 前言 目前的Android开发为了减少编译时间 开发效率 大多都采用模块化 组件化的开发方式 采用这种方式不可避免的将会用到
  • UE4入门序列 01(UE4安装和环境配置)

    1 UE4的安装流程 2 创建一个示例项目 蓝图和C 3 C 的环境设置 4 运行示例项目 1 UE4的安装流程 Epic Games官网下载客户端 注册一个Epic Games的账号 Epic Games客户端包括了Epic公司旗下的Ep
  • vue el-select下拉框,选择后赋值成功,但是框上不显示选中的值的解决办法

    最近在做项目时发现el select下拉框 选择后赋值成功 但是框上不显示选中的值 后来查了下官方文档之后发现原因 vue 无法监听动态新增的属性的变化 需要用 set 来为这些属性赋值 如上图所示 操作人下拉框初始没有值 选择了操作班组之
  • Go语言的跨文件调包

    一 前言 文件的结构如下 go mod main main go util util go 文件在调用其它包的时候 需要在代码中引用其他的函数 包的命名一般都以小写为主 文件中函数的以首字符为大写的函数为共有函数 小写的为私有函数 只能是在
  • SQL增加表的约束(主键、外键、check,唯一)

    以下操作是在已经创建了表之后 进行的约束条件的增加 1 增加check约束条件 alter table 表名 add constraint 约束条件名称 check 约束条件 如 alter table test add constrain
  • 软件工程导论 黑盒测试、白盒测试

    单元测试 集中检测软件设计的最小单元 即模块 测试重点 模块接口 局部数据结构 重要执行通路 出错处理通路 边界条件 代码审查 一次审查可以发现多个错误 可以减少系统验证的总工作量 集成测试 非渐增式测试 将程序作为一个整体 对错误的定位和
  • python-运算符

    除 x除以一 注意整数相除得到的是整数 如4 3结果为1 4 0 3或者4 3 0结果为1 3333333 取整除 返回商的整数 4 3 0的结果为1 0 取模 返回除法的余数 8 3得到2
  • 力扣 214. 最短回文串 一遍过,很舒服(代码做了分层,很容易理解)

    include
  • leecode344反转字符串(附有调试代码)

    package heima study day3 import java util Scanner public class 反转字符串344 public static void main String args Scanner inpu
  • 为什么要使用ConstraintLayout?

    本文为博主原创文章 转载请注明出处 http blog csdn net jingsummer article details 78615360 源码地址 ConstraintLayoutDemo 相信大家对ConstraintLayout