Android 6.0的Launcher3的Hotseat修改

转载参考下:  http://blog.csdn.net/xch520xx/article/details/51285927

最近在公司在处理Launcher桌面,横屏的时候要求桌面的 Hotseat在底部(竖屏的时候Hotseat刚好在底部),而我们刚开始的时候Hotseat却在右侧。之前也处理过相应的问题,一般来说,这个情况可以通过修改分辨率可以解决,可以试着修改build.prop这个属性文件,并推送到系统里面。修改值如下(参考值):

[plain]  view plain  copy
  1. </pre><pre name="code" class="plain">ro.sf.lcd_density=160  

    这个方法可能是系统自适应的结果,当屏幕分辨率调小后,图标都变小,此时横屏将Hotseat放在底部比较合适,相反,如果在屏幕分辨率比较大,hotseat在底部,在一定程度上回让屏幕变窄很不协调,比如之前我们的屏幕是 6*5的,如果放在底部,就变成了6*4,可以想象给人感觉都不好。

    刚才是闲扯了,现在看看代码是怎么处理的。先看hotseat.xml文件这个应该是布局

[html]  view plain  copy
  1. <com.android.launcher3.Hotseat  
  2.     xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:launcher="http://schemas.android.com/apk/res-auto">  
  4.     <com.android.launcher3.CellLayout  
  5.         android:id="@+id/layout"  
  6.         android:layout_width="wrap_content"  
  7.         android:layout_height="match_parent"  
  8.         android:layout_gravity="center" />  
  9. </com.android.launcher3.Hotseat>  


该布局的逻辑主要在Hotseat.Java中,我们继续进去看看

[java]  view plain  copy
  1. public Hotseat(Context context, AttributeSet attrs, int defStyle) {  
  2.         super(context, attrs, defStyle);  
  3.         mLauncher = (Launcher) context;  
  4.         mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout();  
  5.     }  

这是Hotseat的一个构造方法,一眼看去,就知道第4行是横竖屏的判断,在该类的下面有很多都是根据mHasVerticalHotseat的值来判断用相应的参数。既然竖屏的时候hotseat在底部,我们可以尝试将横屏时候的调用竖屏时的布局,这样就可以实现了。我们再去看看里面是怎么判断的。我们进去一看跳转到了 DeviceProfile.java类里面相关代码如下:

[java]  view plain  copy
  1. /** 
  2.      * When {@code true}, hotseat is on the bottom row when in landscape mode. 
  3.      * If {@code false}, hotseat is on the right column when in landscape mode. 
  4.      */  
  5.     boolean isVerticalBarLayout() {  
  6.         return isLandscape && transposeLayoutWithOrientation;  
  7.     }  

看上面的注释,大概就知道,当返回值为true时 hotseat is on the bottom row,当为false时 hotseat is on the right column;这个很接近答案了。

接着看该类的代码:

[java]  view plain  copy
  1. transposeLayoutWithOrientation =  
  2.                 res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);  
[java]  view plain  copy
  1. public DeviceProfile(Context context, InvariantDeviceProfile inv,  
  2.             Point minSize, Point maxSize,  
  3.             int width, int height, boolean isLandscape) {  
  4.   
  5.         this.inv = inv;  
  6.         this.isLandscape = isLandscape;  
  7.         ...  
  8.         ...  
  9.     }  

transposeLayoutWithOrientation是获取一个bool值,在属性配置文件中可以找到,默认为true;
我们看看这个 isLandscape 是在  DeviceProfile类的构造方法里面传入的。
 
我们再继续查找在哪里调用了这个构造方法,最后在InvariantDeviceProfile.java类中找到了: 

[java]  view plain  copy
  1. landscapeProfile = new DeviceProfile(context, this, smallestSize, largestSize,  
  2.                largeSide, smallSide, true /* isLandscape */);  
  3.        portraitProfile = new DeviceProfile(context, this, smallestSize, largestSize,  
  4.                smallSide, largeSide, false /* isLandscape */);  

以上差不多是修改hotseat的相关代码,可以用来借鉴参考下。如有什么问题,还请指教!
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值