
最近在做一个钢琴的东西,关于这个界面如何设计画了很长时间,主要是考虑到针对不同的分辨率,如果只针对一种分辨率的话用绝对布局可以实现,实现的基本思想是每个白色的键的位置是可以计算出来的,屏幕的宽度可以获得到,白键是将屏幕均匀的分成8份,所以每个白键所处的位置是可以得到的,而由于黑键的实现采用的是重写ViewGroup的方法,先计算出每个黑键的位置,然后再执行onLayout方法将黑键放在指定的位置。
布局如下:
<RelativeLayout
android:id="@+id/mClickLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/mPanoClickWhiteOne"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1000"
android:tag="1"
/>
<ImageView
android:id="@+id/mPanoClickWhiteTwo"
android:layout_width="fill

这篇博客讲述了作者在开发Android钢琴应用时,如何设计并实现钢琴界面的过程。主要思路是利用相对布局,根据屏幕宽度将白键均匀分布,并通过自定义ViewGroup来定位黑键。通过计算每个键的位置,确保在不同分辨率的设备上都能正确显示。
最低0.47元/天 解锁文章

5386

被折叠的 条评论
为什么被折叠?



