android 钢琴界面实现

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


最近在做一个钢琴的东西,关于这个界面如何设计画了很长时间,主要是考虑到针对不同的分辨率,如果只针对一种分辨率的话用绝对布局可以实现,实现的基本思想是每个白色的键的位置是可以计算出来的,屏幕的宽度可以获得到,白键是将屏幕均匀的分成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_parent"
	            android:layout_height="fill_parent"
	            android:layout_weight="100
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值