Android2.2-2.3锁屏分析(二)-布局分析

ROM之家

上一节对锁屏幕进行大致的介绍。

这节来分析整个界面的布局。先上图:

Android2.2-2.3锁屏分析(二)-布局分析

分析文件(以竖屏为例):frameworks\base\core\res\res\layout\keyguard_screen_tab_unlock.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tabunlock="http://schemas.android.com/apk/res/com.android.tabunlock"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#70000000"
    android:gravity="center_horizontal"
    android:id="@+id/root">

    <TextView
        android:id="@+id/carrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="10dip"
        android:layout_marginRight="8dip"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:gravity="right|bottom"
        android:textAppearance="?android:attr/textAppearanceMedium"
        />

    <!-- "emergency calls only" shown when sim is missing or PUKd -->
    <TextView
        android:id="@+id/emergencyCallText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/carrier"
        android:layout_alignParentRight="true"
        android:layout_marginTop="0dip"
        android:layout_marginRight="8dip"
        android:text="@string/emergency_calls_only"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/white"
       />

    <!-- time and date -->
    <com.android.internal.widget.DigitalClock android:id="@+id/time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/carrier"
        android:layout_marginTop="52dip"
        android:layout_marginLeft="20dip"
        android:layout_marginBottom="8dip"
        >

        <TextView android:id="@+id/timeDisplay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:ellipsize="none"
            android:textSize="72sp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:shadowColor="#C0000000"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="3.0"
            android:layout_marginBottom="10dip"
            />


        <TextView android:id="@+id/am_pm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/timeDisplay"
            android:layout_alignBaseline="@id/timeDisplay"
            android:singleLine="true"
            android:ellipsize="none"
            android:textSize="22sp"
            android:layout_marginLeft="8dip"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:shadowColor="#C0000000"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="3.0"
            />

    </com.android.internal.widget.DigitalClock>

    <TextView
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/time"
        android:layout_marginLeft="24dip"
        android:textAppearance="?android:attr/textAppearanceMedium"
        />

    <TextView
        android:id="@+id/status1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/date"
        android:layout_marginTop="4dip"
        android:layout_marginLeft="24dip"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:drawablePadding="4dip"
        />

    <TextView
        android:id="@+id/status2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/status1"
        android:layout_marginTop="4dip"
        android:layout_marginLeft="24dip"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:drawablePadding="4dip"
        />

    <TextView
        android:id="@+id/screenLocked"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/status2"
        android:layout_marginLeft="24dip"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_marginTop="12dip"
        android:drawablePadding="4dip"
        />

    <com.android.internal.widget.SlidingTab
        android:id="@+id/tab_selector"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="80dip"
        />

    <!-- emergency call button shown when sim is PUKd and tab_selector is
         hidden -->
    <Button
        android:id="@+id/emergencyCallButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/ic_emergency"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="80dip"
        style="@style/Widget.Button.Transparent"
        android:drawablePadding="8dip"
        android:visibility="gone"
        />

</RelativeLayout>

上面是android2.3源代码。

@+id/carrier:显示运营商信息,没有插入SIM卡时显示“没有SIM卡”,没有信号时会显示“(无服务)”

@+id/emergencyCallText:固定字符串。“只能使用紧急呼叫”,在没有插入SIM卡时显示。

@+id/time:显示时间信息,包括12和24小时制。这里是单独写了一个ViewGroup,后面会专门介绍。

@+id/date:显示日期信息,包括星期。如果需要修改格式,请在对应语言的donottranslate-cldr.xml文件中找到需要的格式

@+id/status1、@+id/status2:分别显示充电、闹钟信息。

@+id/screenLocked:暂未涉及

@+id/tab_selector:滑动解锁,后面单独介绍

@+id/emergencyCallButton:紧急拨号按钮。当没有插入SIM卡时显示。

这里可以对布局进行任意修改,但建议不要修改ID名称,因为上面所显示的都是常用的信息,一般手机都会包括这些。如果确实要删除,请先确定别的类中是否有包含这些控件。比如打电话和接电话界面。

还有一点请注意,这里如果删除或者新增控件,需要全部编译,不能只编译framework层代码。具体什么原因暂时未找到。

相关推荐