Android中的ConstraintLayout约束布局

2023-11-04

ConstraintLayout约束布局

ConstraintLayout有啥好处呢?可以减少布局层次,特别适合复杂的大型布局。可谓是集线性布局和相对布局于一身的荣誉布局。

使用

添加依赖
目前,AndroidStudio新的版本默认就给你上ConstraintLayout了。如果没有的话怎么添加以来呢?

repositories {
google()
}

添加仓库依赖

dependencies {
implementation ‘com.android.support.constraint:constraint-layout:1.1.2’
}

然后就sync一下就好了。

把现有的布局转成约束布局

1、在 Android Studio 中打开您的布局,然后点击编辑器窗口底部的 Design 标签。

2、在 Component Tree 窗口中,右键点击该布局,然后点击 Convert layout to ConstraintLayout。
在这里插入图片描述

一、创建约束布局的规则
  • 每个视图都必须至少有两个约束条件:一个水平约束条件,一个垂直约束条件(不进行水平或者垂直约束的话,默认显示到0,0位置也就是左上角)
  • 只能在共用同一平面的约束手柄与定位点之间创建约束条件。因此,视图的垂直平面(左侧和右侧)只能约束在另一个垂直平面上;而基准线则只能约束到其他基准线上。(简单说视图顶部/底部只能约束顶部或底部,左侧/右侧只能约束左侧或右侧)
  • 每个约束句柄只能用于一个约束条件,但您可以在同一定位点上创建多个约束条件(从不同的视图),也就是说出发只能一个而到达目的地可以多个
二、布局

1、相对布局

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

和我们使用的RelativeLayout布局很相似,表示谁在谁的地方,比如:

  • 相对与父级
<?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">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    
</androidx.constraintlayout.widget.ConstraintLayout>

比如说这样子,顶部相对于父级的顶部约束,开始的位置跟父级开始的位置一样。
在这里插入图片描述
这里的 app:layout_constraintStart_toStartOf="parent"也可以换成 app:layout_constraintLeft_toLeftOf=“parent”
但是他们俩还是有所区别的
left一定是左边,而start不一定,我们的习惯是start从左往右,比如说文字阅读。而某些国家是start从右往左。这个开始方向是跟系统语言有关系的。

  • 同级的相对布局
  <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button2"
        app:layout_constraintLeft_toLeftOf="@id/button"
        app:layout_constraintTop_toBottomOf="@id/button" />

在这里插入图片描述
还有baseLine基线线

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBaseline_toBaselineOf="@id/button"/>

在这里插入图片描述
2.角度定位
相关属性

//围绕的目标
layout_constraintCircle
//距离
layout_constraintCircleRadius
//角度
layout_constraintCircleAngle

比如:

  <Button
        android:id="@+id/earth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我是地球"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="13dp"
        android:layout_marginBottom="51dp"
        android:text="我是月亮"
        app:layout_constraintBottom_toTopOf="@+id/earth"
        app:layout_constraintCircle="@id/earth"
        app:layout_constraintCircleAngle="45"
        app:layout_constraintCircleRadius="120dp"
        app:layout_constraintStart_toEndOf="@+id/earth" />

在这里插入图片描述
3.绝对布局
用于设置控件在ConstraintLayout中并未约束的绝对位置。运行后在真机上是看不到的,只能做到Design时进行预览。
相关属性

layout_editor_absoluteX
layout_editor_absoluteY

例如按钮在x,y的绝对坐标为120dp,如果已经约束的话,绝对布局就不起作用了
在这里插入图片描述
4.margin

相关属性
当前View与另一个View绑定后,另一个View的属性设置为了Gone,则以下属性会生效

layout_goneMarginLeft
layout_goneMarginTop
layout_goneMarginRight
layout_goneMarginBottom
layout_goneMarginStart
layout_goneMarginEnd

<?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">

    <Button
        android:id="@+id/earth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:layout_marginLeft="100dp"
        android:text="我是地球"
        android:visibility="gone"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="@id/earth"
        app:layout_constraintTop_toBottomOf="@id/earth"
        android:text="我是月亮"
        app:layout_goneMarginTop="100dp"
        app:layout_goneMarginLeft="100dp"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

因为textView的左部和顶部绑定Button,所以当button的可见性为gone时app:layout_goneMarginTop=“100dp”
app:layout_goneMarginLeft="100dp"就起作用
在这里插入图片描述

5.偏移
bias就是偏移的意思
相关属性
水平偏移和垂直偏移

layout_constraintHorizontal_bias
layout_constraintVertical_bias

水平方向

    <Button
        android:id="@+id/earth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我是地球"
        app:layout_constraintHorizontal_bias="0.2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

水平偏移20%
在这里插入图片描述
垂直方向

   <Button
        android:id="@+id/earth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我是地球"
        app:layout_constraintVertical_bias="0.2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

垂直方向偏移20%
在这里插入图片描述
6.宽高比
相关属性

layout_constraintDimensionRatio

如果我们要一下宽和高为1:2的控件大小

    <Button
        android:id="@+id/earth"
        android:layout_width="100dp"
        android:layout_height="0dp"
        android:text="我是地球"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="1:2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

在这里插入图片描述
宽高至少得有一个为0,则以另外一个值作为参考进行比例。
7.权重
和之前的LinearLayout布局很相似
相关属性
水平方向的权重,垂直方向的权重

layout_constraintHorizontal_weight
layout_constraintVertical_weight

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

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="button2"
        app:layout_constraintHorizontal_weight="2"
        app:layout_constraintLeft_toRightOf="@id/button1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

在这里插入图片描述
垂直方向同样的用法

链式布局

相关属性

layout_constraintHorizontal_chainStyle
layout_constraintVertical_chainStyle

在这里插入图片描述

  • CHAIN_SPREAD 左右两边距离相等
  • CHAIN_SPREAD_INSIDE 内边距相关
  • Weighted chain 权重链,根据权重占比
  • CHAIN_PACKED 两边等距内容一起
  • package chain with bias 同上,不过有偏移

例子:

 <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="A"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/button2"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="B"
        app:layout_constraintLeft_toRightOf="@id/button1"
        app:layout_constraintRight_toLeftOf="@id/button3"
        app:layout_constraintTop_toTopOf="parent" />


    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="C"
        app:layout_constraintLeft_toRightOf="@id/button2"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

在这里插入图片描述
链头添加样式:

app:layout_constraintHorizontal_chainStyle=“packed”

在这里插入图片描述

app:layout_constraintHorizontal_chainStyle=“spread_inside”

在这里插入图片描述

app:layout_constraintHorizontal_chainStyle="spread"

在这里插入图片描述

尺寸约束

相关属性

layout_constrainedWidth
layout_constrainedHeight
layout_constraintWidth_default
layout_constraintHeight_default
layout_constraintWidth_min 将设置此维度宽的最小尺寸
layout_constraintWidth_max将设置此维度宽的最大尺寸
layout_constraintWidth_percent将此维度的宽大小设置为父维度的百分比
layout_constraintHeight_min 将设置此维度高的最小尺寸
layout_constraintHeight_max将设置此维度高的最大尺寸
layout_constraintHeight_percent将此维度的高大小设置为父维度的百分比

WRAP_CONTENT (添加在 1 . 1中):强制约束
如果维度设置为WRAP_CONTENT,则在 1.1 之前的版本中,它们将被视为文字维度——也就是说,约束不会限制结果维度。虽然通常这已经足够(并且更快),但在某些情况下,您可能希望使用WRAP_CONTENT,但继续强制执行约束以限制结果维度。在这种情况下,您可以添加相应的属性之一:

app:layout_constrainedWidth=“true|false”
app:layout_constrainedHeight=“true|false”

当app:layout_constrainedWidth=“false”

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="A"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/button2"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="B"
        app:layout_constraintLeft_toRightOf="@id/button1"
        app:layout_constraintRight_toLeftOf="@id/button3"
        app:layout_constraintTop_toTopOf="parent" />


    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        app:layout_constrainedWidth="false"
        android:layout_height="wrap_content"
        android:text="CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
        app:layout_constraintLeft_toRightOf="@id/button2"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

在这里插入图片描述
当app:layout_constrainedWidth="true"会强制对button3进行约束,并限制维度
在这里插入图片描述
layout_constrainedHeight 同理
layout_constraintWidth_default值选项有三,是枚举类型
定义如下:

<attr name="layout_constraintWidth_default">
        <enum name="spread" value="0"/>
        <enum name="wrap" value="1"/>
        <enum name="percent" value="2"/>
    </attr>

主要用于设置百分比
在这里插入图片描述
1.宽度为0dp或高度为0dp
l2.ayout_constraintWidth_default为percent,或layout_constraintHeight_default为percent
3.通过layout_constraintHeight_percent 或者layout_constraintWidth_percent 来设置百分比
例如:
宽度占0.7,高度为wrap_content

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        app:layout_constraintWidth_default="percent"
        android:layout_height="wrap_content"
        app:layout_constraintWidth_percent="0.7"
        android:text="CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
        app:layout_constraintLeft_toRightOf="@id/button2"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

在这里插入图片描述
最值限定

  • layout_constraintWidth_min
  • layout_constraintWidth_max
  • layout_constraintHeight_min
  • layout_constraintHeight_max

若内容是动态内容,此时为包裹内容会动态变化宽高,可以通过设置以上几个属性来限定控件的宽高变化

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintHeight_max="50dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_max="200dp" />

在这里插入图片描述

辅助约束

参考线Guideline

可以理解为一个假设的线,实际运行时不会出现。只是你看预览效果时会有
相关属性

//开始
layout_constraintGuide_begin
//结束
layout_constraintGuide_end
//百分比
layout_constraintGuide_percent

例子:
开始距离

 <androidx.constraintlayout.widget.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintGuide_begin="100dp"/>

在这里插入图片描述
方向,默认是水平方向

 <androidx.constraintlayout.widget.Guideline
        android:layout_width="wrap_content"
        android:orientation="vertical"
        android:layout_height="wrap_content"
        app:layout_constraintGuide_begin="100dp"/>

改成垂直方向,如上
百分比,注意,取值[0,1]f

 <androidx.constraintlayout.widget.Guideline
        android:layout_width="wrap_content"
        android:orientation="vertical"
        android:layout_height="wrap_content" 
        app:layout_constraintGuide_percent="0.5"/>

在这里插入图片描述
使用,参考于guide_line
右边连接到guide_line的右边

<androidx.constraintlayout.widget.Guideline
        android:id="@+id/guide_line"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_end="100dp" />

    <Button
        android:id="@+id/earth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我是地球"
        app:layout_constraintRight_toRightOf="@+id/guide_line"
        app:layout_constraintTop_toTopOf="parent" />

在这里插入图片描述

屏障Barrier

举个例子

 <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="30dp"
        android:text="1111111111111111111"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:padding="30dp"
        android:text="22222222222"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/text1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="333333333333333333333333333333333"
        app:layout_constraintLeft_toRightOf="@id/text1"
        app:layout_constraintTop_toTopOf="parent" />

在这里插入图片描述
左边的1和2都是包裹内容,内容动态添加的话会撑大。目前3是以1的右边作为参考。如果2变大,则会与3重叠
例如出现下面情况,这显然不符合我们的要求,此时需要设置一道屏障,相当于一堵墙
在这里插入图片描述

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="30dp"
        android:text="1111111111111111111"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:padding="30dp"
        android:text="22222222222222222222222222222222222"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/text1" />

    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="right"
        app:constraint_referenced_ids="text1,text2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="333333333333333333333333333333333"
        app:layout_constraintLeft_toRightOf="@id/barrier"
        app:layout_constraintTop_toTopOf="parent" />

这样子,就以屏障作为参考了
在这里插入图片描述

Group组

This class controls the visibility of a set of referenced widgets. Widgets are referenced by being added to a comma separated list of ids,

控制一组内容的可见性

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="30dp"
        android:text="1111111111111"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="30dp"
        android:text="22222222222222"
        app:layout_constraintLeft_toRightOf="@id/button1"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="30dp"
        android:text="333333333333333"
        app:layout_constraintLeft_toRightOf="@id/button2"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.constraintlayout.widget.Group
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:constraint_referenced_ids="button1,button3" />

在这里插入图片描述
设置不可见

   <androidx.constraintlayout.widget.Group
        android:layout_width="wrap_content"
        android:visibility="gone"
        android:layout_height="wrap_content"
        app:constraint_referenced_ids="button1,button3" />

就只剩下一个button2了。

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

Android中的ConstraintLayout约束布局 的相关文章

  • 处理 Android 锁屏上的音量变化?

    我想做的是 能够在 android 4 4 上的锁屏上捕获音量增大 减小按钮操作 Google Cast 设计清单 https developers google com cast docs design checklist sender
  • 在名称中使用时间戳时,Android Studio 在构建后无法启动应用程序

    我遇到了 gradle 和 Android Studio 的问题 该问题仅在 Android Studio 中构建时出现 BuildServer 和 Commandline 工作正常 applicationVariants all vari
  • Android向后兼容技术

    我现在在开发基于最新 API 15 ICS 的 15 项活动 Android 应用程序方面取得了进展 现在我发现应用程序的主要功能主义者即使支持 android v4 也不向后兼容 例如 1 fragment事务动画 2 将StringSe
  • 在代码中旋转按钮(或其中的文本)

    我必须通过编码随机旋转按钮 或里面的文本 它是相同的 API级别低于11是否有button setRotate x 好吧 看了一下 答案是 很复杂 您可以使用旧的动画框架旋转按钮 例如像这样 Button button Button fin
  • 毕加索磁盘缓存

    我正在使用 Picasso 从 URL 加载图像 Picasso with getApplicationContext load product getImageUrl into imageView 据我所知 每次都会访问该网址 而不是缓存
  • ListView:防止视图回收

    我有一个使用回收视图的 ListView 我试图阻止视图被回收 所以我使用 setHasTransientState android support v4 view ViewCompatJB setHasTransientState Vie
  • 如何忽略 LeakCanary 中的某些类?

    有人能给我一个如何忽略 LeakCanary 中的某些类的有效示例吗 我正在查看这个示例 以忽略 LeakCanary 中第三方库中的某些类 但我不知道将其放在应用程序中的何处 我把它放在我的应用程序类中 但这些变量和方法有错误 isInA
  • Android CursorAdapter、ListView 和后台线程

    我一直在开发的这个应用程序有包含数兆字节数据的数据库可供筛选 许多活动只是列表视图 通过数据库中的各个级别的数据下降 直到到达 文档 即从数据库中提取并显示在手机上的 HTML 我遇到的问题是 其中一些活动需要能够通过捕获击键并重新运行带有
  • FLAG_ACTIVITY_REORDER_TO_FRONT 被忽略

    我有一个包含项目列表的 FragmentActivity 当应用程序处于后台时 可以推送该项目列表 发生这种情况时 我想创建一个状态栏通知并提醒用户更新 当用户单击通知时 活动应重新排序到前面并显示在屏幕上 同时在列表底部显示新项目 所以我
  • 使用 mupdf android 库导航到特定页面

    我如何使用 muPDF 库导航到特定页面 或者有没有办法让图书馆不记得我最后在那个pdf文件中浏览的是哪一页 Uri uri Uri parse path Intent intent new Intent MainActivity getC
  • 我应该选择的最低 SDK 版本是多少? (截至2018年11月)

    据我所知 android studio 中默认的最小 SDK 设置是 15 我读到我应该增加它 因为没有多少人 或者可能没有 仍在使用该 android 版本 另外 我计划使用 android studio 中的一些新功能 这些功能仅适用于
  • Android Drawable 绘图性能?

    在我看来 我有一个简单的 ARGB 可绘制对象 大约需要 2 毫秒才能绘制 但我可以在 0 5 毫秒内绘制与位图相同的文件 只是一些快速代码 我真的不能认为它是一个选项 优化可绘制对象的绘制速度的最佳方法是什么 这取决于可绘制的数量以及每个
  • 按名称获取 ArrayList

    这是正确的获取方式吗ArrayList
  • 无法登录 Google Play 游戏服务

    我在开发者控制台上使用包名称和正确的签名证书设置了我的游戏 并为其创建了排行榜 但没有创建任何成就 然后 我从以下位置下载了示例 Type A Number Challenge 和 BaseGameUtils https developer
  • BitmapFactory.decodeResource() 忽略 jpg 图像的 inPreferredConfig 选项

    我尝试将jpeg资源图像加载到ARGB 8888格式的位图 BitmapFactory Options opts new BitmapFactory Options opts inPreferredConfig Bitmap Config
  • 从Android客户端登录appengine

    我正在尝试登录应用程序引擎并访问应用程序引擎中的用户服务API 基本上我希望能够看到谁登录了我的 servlet 我正在使用从 android 获取 authtoken 然后从应用程序引擎获取 ASID 或 SACID cookie 的身份
  • 使用 RecyclerView.Adapter 在 onBindViewHolder() 内设置 onItemClickListener

    我有一个自定义对象 学生班 public class Student private String name private String age public String getName return name public void
  • 制作弹跳动画

    我想做图层的弹跳动画 我已经完成了该图层从右到中心的操作 现在我想将其向后移动一点 然后回到中心 这会产生反弹效果 我想我可以用这样的翻译来做到这一点
  • Android Jasper 报告

    Jasper Reporting 可以集成到 Android 应用程序中吗 我正在尝试从 jrxml 文件生成 PDF CSV 文本和 XLS 报告 但是 我没有看到 Android SDK 支持 net sf jasperreports
  • Android Espresso - 如果未选中,请单击复选框

    I have onView withId R id check box perform click 但我只想在尚未选中该复选框时执行此操作 我怎样才能在浓缩咖啡中做到这一点 我还想根据其之前的状态来切换复选框 开关 起初 我尝试用此方法打开

随机推荐

  • QListWidget和QListWidgetItem的简单使用

    QListWidget可以显示一个清单 清单中的每个项目是QListWidgetItem的一个实例 每个项目可以通过QListWidgetItem来操作 可以通过QListWidgetItem来设置每个项目的图像与文字 下面说明3个例子 一
  • 美国数学家维纳智力早熟,11岁就上了大学,他曾在1935-1936年 应邀参加中国清华大学讲学,一次他参加某个重要会议,年轻的脸孔 引人注意,于是有人询问他的年龄,他回答说“我年龄的立方是个4位数

    package day01 import java util HashSet import java util Set 标题 猜年龄 美国数学家维纳智力早熟 11岁就上了大学 他曾在1935 1936年 应邀参加中国清华大学讲学 一次他参加
  • python __file__ 内置属性

    file 内置属性可以获取当前方法所在文件的路径 import random print random file usr lib python3 8 random py 由于import导入的时候是先判断当前路径下有没有import的文件
  • 计算方法-数值积分与微分

    文章目录 一 数值积分的基本思想 代数精度 二 插值型求积公式 插值型求积公式的基本思想 求积公式 插值型求积公式的代数精度 问题 三 牛顿 柯特斯求积公式 牛顿 柯特斯求积公式的引出 已知条件 公式 为什么提出公式中的 b a 柯特斯系数
  • Python——tensorflow2.8猫狗识别

    很早就想做这个猫狗识别的程序 所以跟着唐宇迪教程做了一遍 中间部分参数做了修改 后面预测部分用自己的猫猫图片做了预测 虽然有点问题 但最后还是可以识别出来 问题不大 下面对程序几个部分进行讲解 最后会附上整个程序的附件 一 数据处理 整个训
  • 三步使用bert搭建文本分类器

    不说废话 直接三步搭建最简单的bert文本多标签分类器 1 去官网https github com google research bert 下载一个bert模型 2 搭建bert service https github com hanx
  • 哈希学习简介

    一 背景介绍 1 首先介绍一下最近邻搜索 最近邻搜索问题 也叫相似性搜索 近似搜索 是从给定数据库中找到里查询点最近的点集的问题 给定一个点集 以及一个查询点q 需要找到离q最近的点的集合 在大规模高维度空间的情况下 这个问题就变得非常难
  • android 进程监控 top

    adb shell top h top h Usage top m max procs n iterations d delay s sort column t h m num Maximum number of processes to
  • mybatis-plus自定义分页实现 (精)

    添加pom依赖
  • EVE-NG初始安装及配置_笔记

    1 安装VMware 2 导入EVE的ova镜像 3 初始化配置 ubantu server linux 设置root密码 域名 主机名 IP地址 root eve 123456 123456 主机名 域名 IP地址获取 DHCP STAT
  • mysql数据库管理-mysql分区表管理

    1 分区概述 无论是哪种 MySQL 分区类型 要么分区表上没有主键 唯一键 要么分区表的主键 唯一键都必须包含分区键 也就是说不能使用主键 唯一键字段之外的其他字段分区 例如 emp 表的主键为id字段 在尝试通过store id字段分区
  • React实现拖拽效果

    最近遇到一个拖拽的业务 那么我们需要了解一下拖拽的流程 让我们来实现这个组件吧 一 拖拽流程 编写项目之前我们先了解一下拖拽大致的流程 以及触发的事件 其实拖拽一共分为三个步骤 1 onmousedown 拖拽事件的最开始 在这个简单我们要
  • 发现一个xdotool,是个神器

    xdotool是linux下 类似 按键精灵 的工具 在一些自动测试时 经常用到 以上为xdotool正常使用 比如说 模拟击键a xdotool key a 模拟两个键alt tab xdotool key alt Tab 自动输入wor
  • SeaTunnel本地运行以及kafka发送到redis说明

    下载 Seatunnel2 3 1源码 Idea中的目录结构 编译 通过maven进行代码编译 编译命令 mvn clean package pl seatunnel dist am Dmaven test skip true 编译单个模块
  • 【恶意代码与软件安全分析】(三)dynamic analysis

    恶意代码与软件安全分析 三 virtualbox崩掉了 只能跳过第二章先做第三章了 动态分析 在一个安全的环境下运行恶意软件并观察其行为 分析后输出内容 process Service Behavior 进程创建 进程终止 进程数 netw
  • Vue再学习2_组件开发

    Vue再学习2 组件开发 全局组件 在main js中配置 配置完成之后可以全局使用 1 引入组件对象 import GlobalTitle from components GlobalTitle vue 2 声明全局组件 Vue comp
  • cmd 执行html文件,cmd执行bat文件 cmd文件和bat文件有什么区别?

    cmd怎么执行dos下的bat文件在文件目录直接输入bt4 bat就可以了 记住要输入完整的文件名 包换后缀名 比如 11 bat在D盘根目录 在D gt 后面直接输入11 bat 回车 cmd下执行bat文件的命令 在cmd下执行bat文
  • idea 将springboot项目的Application加入service标签里

    idea 将springboot项目的Application启动器加入service标签里 最终效果图如下 第一步 最开始底部显示没有service服务 添加service 第三步 完成以上操作后底部会这样显示 然后点击 第四步 选择Mav
  • SQL Server [使用SSMS来分离数据库] 奋斗的珂珂~

    分离数据库 分离数据库就是将某个数据库 如student Mis 从SQL Server数据库列表中删除 使其不再被SQL Server管理和使用 但该数据库的文件 MDF 和对应的日志文件 LDF 完好无损 分离成功后 我们就可以把该数据
  • Android中的ConstraintLayout约束布局

    ConstraintLayout约束布局 ConstraintLayout有啥好处呢 可以减少布局层次 特别适合复杂的大型布局 可谓是集线性布局和相对布局于一身的荣誉布局 使用 添加依赖 目前 AndroidStudio新的版本默认就给你上