当前位置:操作系统 > 安卓/Android >>

android 钢琴界面实现

\

近在做一个钢琴的东西,关于这个界面如何设计画了很长时间,主要是考虑到针对不同的分辨率,如果只针对一种分辨率的话用绝对布局可以实现,实现的基本思想是每个白色的键的位置是可以计算出来的,屏幕的宽度可以获得到,白键是将屏幕均匀的分成8份,所以每个白键所处的位置是可以得到的,而由于黑键的实现采用的是重写ViewGroup的方法,先计算出每个黑键的位置,然后再执行onLayout方法将黑键放在指定的位置。

布局如下:


[html]
<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="1000" 
            android:tag="2" 
            /> 
        <ImageView 
            android:id="@+id/mPanoClickWhiteThree" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:layout_weight="1000" 
            android:tag="3" 
            /> 
        <ImageView 
            android:id="@+id/mPanoClickWhiteFour" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:layout_weight="1000" 
            android:tag="4" 
            /> 
        <ImageView  
            android:id="@+id/mPanoClickWhiteFive" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:layout_weight="1000" 
            android:tag="5" 
            /> 
        <ImageView  
            android:id="@+id/mPanoClickWhiteSix" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:layout_weight="1000" 
            android:tag="6" 
            /> 
        <ImageView  
            android:id="@+id/mPanoClickWhiteSeven" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:layout_weight="1000" 
            android:tag="7" 
            /> 
        <ImageView 
            android:id="@+id/mPanoClickWhiteEight" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:layout_weight="1000" 
            android:tag="8" 
            /> 
    </LinearLayout> 
    <com.example.crazypano.view.BlackLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"> 
        <ImageView 
            android:id="@+id/mPanoClickBlackOne" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
        &

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,