歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android中如何讓控件居中

Android中如何讓控件居中

日期:2017/3/1 10:13:11   编辑:Linux編程

測試部報告鎖屏界面裡,設置鎖屏的那個控件位置不好,有點偏下。以至於設置的時候,圖標都在界外了。

打開packages/app/Settings裡的res/layout-sw720dp/lockscreen_targets.xml

對於橫屏和豎屏兩種情況,其實應該定義兩個目錄一種叫做land,另一種叫做port(都是縮寫),分別對應橫屏和豎屏。

這裡就增加一個目錄layout-sw720dp-land/作為橫屏的配置, layout-sw720dp為豎屏。

對於豎屏的情況

--- a/res/layout-sw720dp/lockscreen_targets.xml
+++ b/res/layout-sw720dp/lockscreen_targets.xml
@@ -26,7 +26,7 @@
Android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
- android:gravity="left|top"
+ android:gravity="top"
prvandroid:targetDrawables="@*android:array/lockscreen_targets_with_camera"
prvandroid:targetDescriptions="@*android:array/lockscreen_target_descriptions_with_camera"
prvandroid:directionDescriptions="@*android:array/lockscreen_direction_descriptions"


對於橫屏

將+ android:gravity="top"改為+ android:gravity="left".

就可以居中顯示了。

更保險的方法是

橫屏: android:gravity="left|center_vertical"

豎屏:android:gravity="top|center_horizontal"

Copyright © Linux教程網 All Rights Reserved