作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道我的主线程需要做很多事情,但是我正在寻找解决方法。
这是我的应用程序的结构:
当前,我有我的主要 Activity ,它具有6个可单击的 ImageView (用于打开新 Activity ),当其中一个 Activity 被打开时会发生问题。在本 Activity 中,我将使用带有3个选项卡的SlidingTabLayout。
这是我要实现的目标:
我正在用可绘制图形(形状)创建钢琴
例如,这是黑键:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#FF000000" />
<solid
android:color="#FF000000"/>
</shape>
<ImageView
android:layout_width="8dp"
android:layout_height="37dp"
android:layout_marginLeft="40dp"
android:layout_marginStart="10.5dp"
android:src="@drawable/key_black" />
最佳答案
因此,如上所述,我将为钢琴创建一个基本图像,并根据当前按下的键对其进行调整。下面的代码显示了一般的想法:从R.drawable加载基本图像,使用索引的按下键以及图像的大小创建Paths,绘制路径,返回图像。如果您需要澄清,请告诉我。
public Bitmap getPianoImage(Context context, int[] pressedKeyIndices){
Bitmap pianoImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.pianoBase);
Canvas canvas = new Canvas(pianoImage);
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL);
for(int pressedKeyIndex : pressedKeyIndices){
Path path = getPathForKeyIndex(pressedKeyIndex, pianoImage.getWidth(), pianoImage.getHeight());
canvas.drawPath(path, paint);
}
return pianoImage;
}
private Path getPathForKeyIndex(int idx, int w, int h){
Path path = new Path();
switch(idx){
case 0:
path.moveTo(0f*w, 0f*h); // used for first point
path.lineTo(0f*w, 1f*h);
path.lineTo(0.1f*w, 1f*h);
path.lineTo(0.1f*w, 0.5f*h);
path.lineTo(0.08f*w, 0.5f*h);
path.lineTo(0.08f*w, 0f*h);
path.lineTo(0f*w, 0f*h);
break;
case 1: ...
}
return path;
}
关于android - Android-应用程序可能在其主线程上做了很多工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38238498/
我是一名优秀的程序员,十分优秀!