零碎知识点

主题样式

<style name="AppTheme" parent="BaseNoActionBarTheme">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/app_color_grey</item>
    <item name="colorPrimaryDark">@color/app_color_grey</item>
    <item name="colorAccent">@color/app_color_grey</item>
</style>
<style name="BaseNoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar" />

1.colorPrimary 应用的主要色调,actionBar默认使用该颜色,Toolbar导航栏的底色

2.colorPrimaryDark 应用的主要暗色调,statusBarColor默认使用该颜色

3.statusBarColor 状态栏颜色,默认使用colorPrimaryDark

4.windowBackground 窗口背景颜色

5.navigationBarColor 底部栏颜色

6.colorForeground 应用的前景色,ListView的分割线,switch滑动区默认使用该颜色

7.colorBackground 应用的背景色,popMenu的背景默认使用该颜色

8.colorAccent CheckBox,RadioButton,SwitchCompat等一般控件的选中效果默认采用该颜色

9.colorControlNormal CheckBox,RadioButton,SwitchCompat等默认状态的颜色。

10.colorControlHighlight 控件按压时的色调

11.colorControlActivated 控件选中时的颜色,默认使用colorAccent

12.colorButtonNormal 默认按钮的背景颜色

13.editTextColor:默认EditView输入框字体的颜色。

14.textColor Button,textView的文字颜色

15.textColorPrimaryDisableOnly RadioButton checkbox等控件的文字

16.textColorPrimary 应用的主要文字颜色,actionBar的标题文字默认使用该颜色

17.colorSwitchThumbNormal: switch thumbs 默认状态的颜色. (switch off)

控件

TextView
1、SpannableStringBuilder 、SpannableString
https://www.cnblogs.com/guanxinjing/p/11227711.html

String content ="先帝创业未半而中道崩殂,今天下三分,益州疲弊,此诚危急存亡之秋也。";
SpannableString spannableString = new SpannableString(content);
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FFFF0C00"))
    , content.indexOf("创业")
    , content.indexOf("而中")
    , Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
mTextView.setText(spannableString);

SpannableStringBuilder 的功能使用,这个类是用于实现多个SpannableString文字拼接的。

上面的span只是一些常用的span演示,但是其实还有更多的span可以选择和使用,他们都在

这个目录中.在这个目录下还有以下这些span

备注:Span跟TextView的ellipsize有冲突,超长不会有省略号、也不会完全显示。

ConstraintLayout
1、实现左侧TextView宽度自适应并且可以显示右侧TextView的布局
效果展示

(原创)实现左侧TextView宽度自适应并且可以显示右侧TextView的布局_uniapp中textview宽度设置自适应-CSDN博客

先来看看上面的效果
左侧的文字宽度是自适应的,但是右侧又有一个TextView
左侧的文字被限制不能把右侧的挤出屏幕外面
所以如果左侧文字超过指定宽度后多余部分就用省略号表示
实际开发中这种情况在一些列表的item中用的比较多
但实际实现的时候会发现
左侧的总是会把右侧的给挤出去
后来用到了ConstraintLayout布局的链条样式来解决这个问题
<?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=".MainActivity">


  <TextView
    android:id="@+id/title1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="左侧文字较短时:"
    android:textStyle="bold"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


  <TextView
    android:id="@+id/left1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:ellipsize="end"
    android:maxLines="1"
    android:text="左侧文字"
    android:padding="4dp"
    android:textColor="#f00"
    app:layout_constraintEnd_toStartOf="@+id/right1"
    app:layout_constraintHorizontal_bias="0"
    app:layout_constraintHorizontal_chainStyle="packed"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/title1"
    app:layout_constraintWidth_default="wrap" />

  <TextView
    android:id="@+id/right1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:text="右侧文字"
    android:background="@drawable/shapetest"
    android:padding="4dp"
    android:textColor="#000"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/left1"
    app:layout_constraintTop_toBottomOf="@+id/title1" />


  <TextView
    android:id="@+id/title2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:text="左侧文字较长时:"
    android:textStyle="bold"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/left1" />


  <TextView
    android:id="@+id/left2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:ellipsize="end"
    android:maxLines="1"
    android:padding="4dp"
    android:text="左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字"
    android:textColor="#f00"
    app:layout_constraintEnd_toStartOf="@+id/right2"
    app:layout_constraintHorizontal_bias="0"
    app:layout_constraintHorizontal_chainStyle="packed"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/title2"
    app:layout_constraintWidth_default="wrap" />

  <TextView
    android:id="@+id/right2"
    android:layout_width="wrap_content"
    android:background="@drawable/shapetest"
    android:padding="4dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:text="右侧文字"
    android:textColor="#000"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/left2"
    app:layout_constraintTop_toBottomOf="@+id/title2" />

</androidx.constraintlayout.widget.ConstraintLayout>


app:layout_constraintHorizontal_chainStyle="packed" 使链条上的元素都打包到一起
app:layout_constraintHorizontal_bias="0"  使左侧控件最左侧对齐
app:layout_constraintWidth_default="wrap" 使左侧文字自适应大小并且不超过约束限制,默认是“spread”,会占用所有符合约束的控件


LinearLayout解决办法

<?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=".MainActivity">


  <TextView
    android:id="@+id/title1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="左侧文字较长时:"
    android:textStyle="bold"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

  <androidx.appcompat.widget.LinearLayoutCompat
    android:id="@+id/ll1"
    android:layout_width="0dp"
    android:layout_marginTop="10dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/title1"
    android:orientation="horizontal"
    android:layout_height="wrap_content">
    <androidx.appcompat.widget.LinearLayoutCompat
      android:layout_width="wrap_content"
      android:orientation="horizontal"
      android:layout_height="wrap_content">
      <TextView
        android:id="@+id/left1"
        android:padding="4dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ellipsize="end"
        android:maxLines="1"
        android:text="左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字左侧文字"
        android:textColor="#f00"
     />

      <TextView
        android:id="@+id/right1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="右侧文字"
        android:textColor="#000"
        android:padding="4dp"
        android:background="@drawable/shapetest"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/left1"
        app:layout_constraintTop_toBottomOf="@+id/title1" />

    </androidx.appcompat.widget.LinearLayoutCompat>
  </androidx.appcompat.widget.LinearLayoutCompat>
</androidx.constraintlayout.widget.ConstraintLayout>

2、magin生效的条件是有约束
3、难点:同一行有多个View可能Gone,怎么设置margin

RecyclerView的GridLayoutManager

RecyclerView+GridLayoutManager+ItemDecoration

网络

Retorfit

1、定义接口api

2、创建Retorfit实例

3、发送请求

每个模块封装一套,定义一个接口使用注解配置请求。定义一个接口申请各种请求,定义一个实现类实现具体请求。再定义一个repository再次包装各种请求,在定义请求页面跟每一页的数据个数等。

MVVM
 

ViewModel

定义一个BaseViewModel,定义多个LiveData通知加载空页面、无网络页面、内容等

再定义个DataViewModel,定义多个LiveData提示比如toast、显示正在加载、取消加载等。封装请求逻辑,回调留给子类实现。

连续postValue,只有最后一次才会收到

性能

内存泄漏

项目中添加leakcanary

kotlin

内联函数inline:在编译的时候会拷贝函数的内容到调用处,因为调用方法会创建方法对象耗时间,内联函数等于是空间换时间

泛型

  • 22
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值