美文网首页
usage point

usage point

作者: 小虫虫奇遇记 | 来源:发表于2020-08-11 10:24 被阅读0次

View相关

  1. 有父View getWidth 小于 child View的场景吗?
    答:ScrollView 只能有一个子View, 对于HorizontalScrollView,如果内容超出屏幕,ScrollView.getWidth 等于屏幕宽度,子View的宽度就是实际内容的宽度。

screenWidth :720
scrollView.getWidth: 720
scrollView.getMeasuredWidth:720
child getMeasuredWidth: 1010
child.getWidth: 1010

  1. TextView根据内容自动调整字体大小:AutoSizing 使用如下,可以设置最大,最小和变动粒度,预设尺寸。
    app:autoSizeTextType设置自动缩放是否开启
    ⚠️ TextView必须限定尺寸;EditText不能使用;singleLine属性冲突,可用maxLines;可预设尺寸范围 app:autoSizePresetSizes

<AppCompatTextView
android:id="@+id/text_message_to_be_send"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/color_333333"
android:textSize="22sp"
android:textStyle="bold"
app:autoSizeTextType="uniform"
app:autoSizeMaxTextSize="22sp"
app:autoSizeMinTextSize="18sp"
app:autoSizeStepGranularity="2sp"
tools:text="I'll be right there, please wait a moment, thank you, " />

  1. 多图片轮播
  mVoicePlayImageView.setImageResource(R.drawable.im_voice_play_animation)

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/voice_message_1" android:duration="500" />
<item android:drawable="@drawable/voice_message_2" android:duration="500" />
<item android:drawable="@drawable/voice_message_3" android:duration="500" />
</animation-list>

  1. 设置了点击效果背景的控件,需代码触发
    textView.isSelected = ! textView.isSelected

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bg_review_dialog_option_item_desc_checked" android:state_selected="true" />
<item android:drawable="@drawable/bg_review_dialog_option_item_desc_normal" />
</selector>

  1. dialog:点击屏幕外,返回键是否消失?
    dialog.setCancelable(false);dialog弹出后会点击屏幕或物理返回键,dialog不消失
    dialog.setCanceledOnTouchOutside(false);
    dialog弹出后会点击屏幕,dialog不消失;点击物理返回键dialog消失

  2. OnGlobalLayoutListener 及时反注册

7.文字翻译是否有超长情况?超长处理?见AppCompatTextView

8.LinearLayout可通过设置android:layoutDirection = "rtl"改变布局方向为从右到左。

  1. View.setPivotX()和setPivotY()方法可设置属性动画(ScaleX,scaleY)的旋转中心点

10,动画插值器:改变动画过程中速度;不设置默认匀速。

ObjectAnimator scaleX = ObjectAnimator.ofFloat(mView, "scaleX", 0.0f, 1.05f);
scaleY.setInterpolator(new AccelerateDecelerateInterpolator());

11.DrawerLayout默认会拦截上层传来的touch事件,需要重写事件拦截方法,控制只在抽屉打开时响应屏幕触摸事件。

@Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        //抽屉关闭的情况下透传点击事件
        if (isDrawerOpen(GravityCompat.END)) {
            return super.onInterceptTouchEvent(ev);
        } else {
            return false;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (isDrawerOpen(GravityCompat.END)) {
            return super.onTouchEvent(ev);
        } else {
            return false;
        }
    }

子View无法响应触摸事件,一般有几种情况:

  • 事件被父容器拦截了
  • 自身不处理:onTouchEvent返回false

功能类

  1. SynchronizedPool:可复用对象池,避免频繁创建对象。如请求或者加载相关类。

相关文章

网友评论

      本文标题:usage point

      本文链接:https://www.haomeiwen.com/subject/ubcrrktx.html