DeYi 技术博客

总结&记录


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

android drawable shape

发表于 2017-09-28 | 分类于 编程 , android , android studio , res , drawable

文档

形状可绘制对象

1
2
3
4
oval
英 [ˈəʊvl] 美 [ˈoʊvl]
adj.椭圆形的;卵形的
n.椭圆形;椭圆运动场(等);椭圆,美式足球用球;[物]卵形线

语法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] >
<corners
android:radius="integer"
android:topLeftRadius="integer"
android:topRightRadius="integer"
android:bottomLeftRadius="integer"
android:bottomRightRadius="integer" />
<gradient
android:angle="integer"
android:centerX="float"
android:centerY="float"
android:centerColor="integer"
android:endColor="color"
android:gradientRadius="integer"
android:startColor="color"
android:type=["linear" | "radial" | "sweep"]
android:useLevel=["true" | "false"] />
<padding
android:left="integer"
android:top="integer"
android:right="integer"
android:bottom="integer" />
<size
android:width="integer"
android:height="integer" />
<solid
android:color="color" />
<stroke
android:width="integer"
android:color="color"
android:dashWidth="integer"
android:dashGap="integer" />
</shape>

设置边框

设置边框时,shape,的预览图里看不到,需要到实际使用时的布局里查看

背景色渐变

android 背景渐变色(shape,gradient)
shape是用来定义形状的,gradient定义该形状里面为渐变色填充,startColor起始颜色,endColor结束颜色,angle表示方向角度。
当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。

android color state list

发表于 2017-09-28 | 分类于 编程 , android , android studio , res , color-state-list

Color State List Resource

A ColorStateList is an object you can define in XML that you can apply as a color, but will actually change colors, depending on the state of the View object to which it is applied. For example, a Button widget can exist in one of several different states (pressed, focused, or neither) and, using a color state list, you can provide a different color during each state.

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:color="hex_color"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_window_focused=["true" | "false"] />
</selector>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true"
android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button_text"
android:textColor="@color/button_text" />

对比 State List Drawable

例子(视频发布时的截图按钮):一个 TextView 需要设置,控件按下状态的,
1) 文本颜色, res/color/color-selector.xml
2) 背景,
3) drawableLeft

android 资源

发表于 2017-09-28 | 分类于 编程 , android , android studio , res

资料

Resource Types
More Resource Types

Resource Types

Each of the documents in this section describe the usage, format and syntax for a certain type of application resource that you can provide in your resources directory (res/).

  1. Animation Resources
    Define pre-determined animations.
    Tween animations are saved in res/anim/ and accessed from the R.anim class.
    Frame animations are saved in res/drawable/ and accessed from the R.drawable class.
  2. Color State List Resource
    Define a color resources that changes based on the View state.
    Saved in res/color/ and accessed from the R.color class.
  3. Drawable Resources
    Define various graphics with bitmaps or XML.
    Saved in res/drawable/ and accessed from the R.drawable class.
  4. Layout Resource
    Define the layout for your application UI.
    Saved in res/layout/ and accessed from the R.layout class.
  5. Menu Resource
    Define the contents of your application menus.
    Saved in res/menu/ and accessed from the R.menu class.
  6. String Resources
    Define strings, string arrays, and plurals (and include string formatting and styling).
    Saved in res/values/ and accessed from the R.string, R.array, and R.plurals classes.
  7. Style Resource
    Define the look and format for UI elements.
    Saved in res/values/ and accessed from the R.style class.
  8. Font Resources
    Define font families and include custom fonts in XML.
    Saved in res/font/ and accessed from the R.font class.
  9. More Resource Types
    Define values such as booleans, integers, dimensions, colors, and other arrays.
    Saved in res/values/ but each accessed from unique R sub-classes (such as R.bool, R.integer, R.dimen, etc.).

More Resource Types

This page defines more types of resources you can externalize, including:

  1. Bool
    XML resource that carries a boolean value.
  2. Color
    XML resource that carries a color value (a hexadecimal color).
  3. Dimension
    XML resource that carries a dimension value (with a unit of measure).
  4. ID
    XML resource that provides a unique identifier for application resources and components.
  5. Integer
    XML resource that carries an integer value.
  6. Integer Array
    XML resource that provides an array of integers.
  7. Typed Array
    XML resource that provides a TypedArray (which you can use for an array of drawables)

android drawable resource

发表于 2017-09-28 | 分类于 编程 , android , android studio , res , drawable

资料

可绘制对象资源
可绘制对象资源是一般概念,是指可在屏幕上绘制的图形,以及可以使用 getDrawable(int) 等 API 检索或者应用到具有 android:drawable 和 android:icon 等属性的其他 XML 资源的图形。

多种不同类型的可绘制对象

  1. 位图文件
    位图图形文件(.png、.jpg 或 .gif)。创建 BitmapDrawable。
  2. 九宫格文件
    具有可拉伸区域的 PNG 文件,允许根据内容调整图像大小 (.9.png)。创建 NinePatchDrawable。
  3. 图层列表
    管理其他可绘制对象阵列的可绘制对象。它们按阵列顺序绘制,因此索引最大的元素绘制在顶部。创建 LayerDrawable。
  4. 状态列表
    此 XML 文件为不同状态引用不同位图图形(例如,按下按钮时使用不同的图像)。创建 StateListDrawable。
  5. 级别列表
    此 XML 文件用于定义管理大量备选可绘制对象的可绘制对象,每个可绘制对象都分配有最大的备选数量。创建 LevelListDrawable。
  6. 转换可绘制对象
    此 XML 文件用于定义可在两种可绘制对象资源之间交错淡出的可绘制对象。创建 TransitionDrawable。
  7. 插入可绘制对象
    此 XML 文件用于定义以指定距离插入其他可绘制对象的可绘制对象。当视图需要小于视图实际边界的背景可绘制对象时,此类可绘制对象很有用。
  8. 裁剪可绘制对象
    此 XML 文件用于定义对其他可绘制对象进行裁剪(根据其当前级别值)的可绘制对象。创建 ClipDrawable。
  9. 缩放可绘制对象
    此 XML 文件用于定义更改其他可绘制对象大小(根据其当前级别值)的可绘制对象。创建 ScaleDrawable
  10. 形状可绘制对象
    此 XML 文件用于定义几何形状(包括颜色和渐变)。创建 ShapeDrawable。

另请参阅动画资源文档,了解如何创建 AnimationDrawable。

注:颜色资源也可用作 XML 中的可绘制对象。例如,在创建状态列表可绘制对象时,可以引用 android:drawable 属性的颜色资源 (android:drawable=”@color/green”)。

android drawable resource selector

发表于 2017-09-28 | 分类于 编程 , android , android studio , res , drawable

资料

状态列表
此 XML 文件为不同状态引用不同位图图形(例如,按下按钮时使用不同的图像)。创建 StateListDrawable。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize=["true" | "false"]
android:dither=["true" | "false"]
android:variablePadding=["true" | "false"] >
<item
android:drawable="@[package:]drawable/drawable_resource"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_hovered=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_activated=["true" | "false"]
android:state_window_focused=["true" | "false"] />
</selector>

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:state_hovered="true"
android:drawable="@drawable/button_focused" /> <!-- hovered -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
1
2
3
4
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/button" />

change-background-image-of-button-when-clicked-focused

1
2
3
4
5
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/your_imagename_while_focused"/>
<item android:state_pressed="true" android:drawable="@drawable/your_imagename_while_pressed" />
<item android:drawable="@drawable/image_name_while_notpressed" /> //means normal
</selector>

警告

1
2
3
4
5
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_fair_off" />
<item android:state_pressed="true" android:drawable="@drawable/ic_fair_off_selected" />
</selector>

This item is unreachable because a previous item (item #1) is a more general match than this one (Earlier item which masks item)

对比 color-state-list

ImagePadMix getBlendBitmap 在一些机器上 输出的BMP是花的

发表于 2017-09-27 | 分类于 编程 , android , 3rdParty , lansosdk

情景 截取视频的封面时添加上效果视频的截图

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private void mixBmp() {
if (requestPermission()) {
return;
}
Bitmap mainJpg = BitmapFactory.decodeFile("/sdcard/main.jpg");
Bitmap effectJpg = BitmapFactory.decodeFile("/sdcard/effect.jpg");
ImagePadMix imagePadMix = new ImagePadMix(this);
if (imagePadMix.prepare(mainJpg.getWidth(), mainJpg.getHeight())) {
Bitmap resBmp = imagePadMix.getBlendBitmap(mainJpg, effectJpg);
imageView.setImageBitmap(resBmp);
try {
resBmp.compress(Bitmap.CompressFormat.JPEG, 70, new FileOutputStream("/sdcard/image-pad-mix.jpg"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}

main.jpg
effect.jpg
mix-result

出问题的手机列表

  1. HMD Global Oy TA-1000
  2. 乐视 MAX

没有问题的手机列表

  1. Xiaomi Redmi Note 4
  2. Meizu M1 E
  3. OPPO A37m

真正的原因

1080 实际的图片高度是 1088
因为你发给我的图片, 高度不是32的倍数

ffmpeg 截图

发表于 2017-09-27 | 分类于 编程 , ffmpeg

ffmpeg视频合并、格式转换、截图

Attempt to perform seekTo in wrong state

发表于 2017-09-27 | 分类于 编程 , android , android sdk , android.media.MediaPlayer

出错情景

1
2
3
4
5
6
7
8
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.pause();
mediaPlayer.seekTo(10 * 1000); // 如果只调用 seek 可正常播放
mainThreadHandler.sendEmptyMessage(MSG_CODE_PLAYER_PREPARED);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
09-27 13:19:14.361 21032-21032/com.lansoeditor.demo E/MediaPlayer: pause called in state 8
09-27 13:19:14.361 21032-21032/com.lansoeditor.demo E/MediaPlayer: error (-38, 0)
09-27 13:19:14.361 21032-21032/com.lansoeditor.demo E/MediaPlayer: Attempt to perform seekTo in wrong state: mPlayer=0xdccaf300, mCurrentState=0
09-27 13:19:14.361 21032-21032/com.lansoeditor.demo E/MediaPlayer: error (-38, 0)
09-27 13:19:14.448 21032-21032/com.lansoeditor.demo E/MediaPlayer: Attempt to perform seekTo in wrong state: mPlayer=0xdccaf300, mCurrentState=0
09-27 13:19:14.448 21032-21032/com.lansoeditor.demo E/MediaPlayer: error (-38, 0)
09-27 13:19:14.450 21032-21032/com.lansoeditor.demo E/MediaPlayer: start called in state 0
09-27 13:19:14.450 21032-21032/com.lansoeditor.demo E/MediaPlayer: error (-38, 0)
09-27 13:19:14.451 21032-21032/com.lansoeditor.demo E/MediaPlayer: Error (-38,0)
09-27 13:19:14.452 21032-21032/com.lansoeditor.demo E/MediaPlayer: Error (-38,0)
09-27 13:19:14.467 21032-21032/com.lansoeditor.demo E/MediaPlayer: Error (-38,0)
09-27 13:19:14.467 21032-21032/com.lansoeditor.demo E/MediaPlayer: Error (-38,0)

如果出现这个错误再调用 mediaPlayer.start() ,会立即产生 MediaPlayer.OnCompletionListener 结束事件

1
2
3
4
5
6
7
8
mplayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (mplayer != null && mplayer.isPlaying()) { 防止死循环
rePlay();
}
}
});

参考

android-mediaplyer-seekto-inside-onprepared
MediaPlayer error (-38, 0)

Android 字符串资源 Formatting and Styling

发表于 2017-09-27 | 分类于 编程 , android , android studio , res , string

文档

Formatting and Styling

例子:

1
2
3
4
<string name="good_example">This\'ll work</string>
<string name="good_example_2">"This'll also work"</string>
<string name="bad_example">This doesn't work</string>
<!-- Causes a compile error -->
1
2
3
4
5
<string name="good_example">This is a \"good string\".</string>
<string name="bad_example">This is a "bad string".</string>
<!-- Quotes are stripped; displays as: This is a bad string. -->
<string name="bad_example_2">'This is another "bad string".'</string>
<!-- Causes a compile error -->
1
2
3
4
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

Resources res = getResources();
String text = res.getString(R.string.welcome_messages, username, mailCount);

主视频旋转 90 度后 附加视频方向不一致了

发表于 2017-09-27 | 分类于 编程 , android , 3rdParty , lansosdk

情景

主视频: 1920x1080 rotation 90度
附加视频: 540x960 rotation 0度

  1. 使用 MediaPlayer + DrawPadView 实现播放,
  2. 使用 TwoVideoLayer 实现同时播放主视频和附加视频
    drawPadView.addTwoVideoLayer(mediaPlayer.getVideoWidth(), mediaPlayer.getVideoHeight());

结果如下图:
TwoVideoLayer-error-rotate

附加视频(蝴蝶)横着播放了

暂时修改方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public void addEffect(String effectPath) {
if (effectPlayer == null) {
effectPlayer = new MediaPlayer();
} else {
effectPlayer.stop();
effectPlayer.reset();
}
try {
effectPlayer.setDataSource(effectPath);
twoVideoLayer.setDisplayTexture2(true);
//当前没有完全解决, 只是时间关系, 规避了一下, 可以通过这样来矫正下角度
//更新了 D:\work\lanso.demo\app\libs\lansongeditor_hx.jar
if (mainVideoInfo.vRotateAngle == 90) {
twoVideoLayer.setSecondVideoMirror(Rotation.ROTATION_270, true, false);
} else if (mainVideoInfo.vRotateAngle == 270) {
twoVideoLayer.setSecondVideoMirror(Rotation.ROTATION_90, true, false);
}
effectPlayer.setSurface(new Surface(twoVideoLayer.getVideoTexture2()));
effectPlayer.prepare();
effectPlayer.start();

} catch (Exception e) {
Log.e(TAG, "播放特效失败", e);
}
}
1…3456

wxiang

音视频、Android、C/C++

54 日志
37 分类
43 标签
© 2019 wxiang
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.2