---
title: "virtual<一>"
author: "ping8080"
date: "2011-10-18T10:20:55Z"
tags: []
categories: ["移动开发"]
slug: "virtual"
draft: false
lastmod: "2011-10-18T10:21:46Z"
id: 1198994
url: "https://ping8080.iteye.com/blog/1198994"
---

1，创建如下新文件

froyo\\frameworks\\base\\core\\res\\res\\layout\\control\_panel.xml 代码如下  
&lt;?xml version="1.0" encoding="utf-8"?&gt;  
&lt;!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");  
     you may not use this file except in compliance with the License.  
     You may obtain a copy of the License at  
   
          [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)  
   
     Unless required by applicable law or agreed to in writing, software  
     distributed under the License is distributed on an "AS IS" BASIS,  
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
     See the License for the specific language governing permissions and  
     limitations under the License.  
\--&gt;

&lt;!--  
This is the basic layout for a screen, with all of its features enabled.  
\--&gt;

&lt;!-- Title bar and content --&gt;  
&lt;com.android.server.status.SystemMenuBarView  xmlns:android="[http://schemas.android.com/apk/res/android](http://schemas.android.com/apk/res/android)"  
    android:fitsSystemWindows="true"  
    android:orientation="vertical"  
    android:layout\_width="match\_parent"  
    android:layout\_height="match\_parent"  
    android:layout\_gravity="center"  
&gt;  
    &lt;!-- Title bar --&gt;  
        &lt;ImageView android:id="@+id/panel1"  
            android:layout\_width="wrap\_content"  
            android:layout\_height="wrap\_content"  
            android:layout\_weight="1"  
            android:src="@drawable/panel\_back"  
            android:padding="2dip"  
        /&gt;  
        &lt;ImageView android:id="@+id/panel2"  
            android:layout\_width="wrap\_content"  
            android:layout\_height="wrap\_content"  
            android:layout\_weight="1"  
            android:src="@drawable/panel\_search"  
            android:padding="2dip"  
        /&gt;  
        &lt;ImageView android:id="@+id/panel3"  
            android:layout\_width="wrap\_content"  
            android:layout\_height="wrap\_content"  
            android:layout\_weight="1"  
            android:src="@drawable/panel\_menu"  
            android:padding="2dip"        
        /&gt;  
        &lt;ImageView android:id="@+id/panel4"  
            android:layout\_width="wrap\_content"  
            android:layout\_height="wrap\_content"  
            android:layout\_weight="1"  
            android:src="@drawable/panel\_home"  
            android:padding="2dip"        
        /&gt;

&lt;/com.android.server.status.SystemMenuBarView&gt;

 

另外 添加布局文件对应的图片资源文件，分竖屏和横屏

 

froyo\\frameworks\\base\\services\\java\\com\\android\\server\\status\\SystemMenuBarView.java 代码如下

 

 

package com.android.server.status;

import android.content.Context;  
import android.content.res.Configuration;  
import android.util.AttributeSet;  
import android.util.Log;  
import android.widget.ImageView;  
import android.widget.LinearLayout;

import com.android.internal.R;

public class SystemMenuBarView extends LinearLayout {  
    private Context mContext;  
    private int mOrientation = -1;  
    private int mCount = 0;  
    private ImageView iv1, iv2, iv3, iv4;  
     
    public SystemMenuBarView(Context context) {  
        super(context);  
        // TODO Auto-generated constructor stub  
        this.mContext = context;  
    }  
     
    public SystemMenuBarView(Context context, AttributeSet attrs) {  
        super(context, attrs);  
        // TODO Auto-generated constructor stub  
    }

    @Override  
    protected void onFinishInflate() {  
        super.onFinishInflate();  
        iv1 = (ImageView)findViewById(R.id.panel1);  
        iv2 = (ImageView)findViewById(R.id.panel2);  
        iv3 = (ImageView)findViewById(R.id.panel3);             
        iv4 = (ImageView)findViewById(R.id.panel4);

    }

    @Override  
    protected void onConfigurationChanged(Configuration newConfig) {  
        // TODO Auto-generated method stub  
        if (mOrientation != newConfig.orientation){  
             
            //Log.i("orie", "mCount:" + mCount++ + "   mOrientation: " + mOrientation + "      newConfig.orientation: " + newConfig.orientation);  
            mOrientation = newConfig.orientation;  
            if (newConfig.orientation==Configuration.ORIENTATION\_LANDSCAPE){  
                Log.i("orie", "land");  
                setOrientation(LinearLayout.VERTICAL);  
                iv1.setImageResource(R.drawable.panel\_back);  
                iv2.setImageResource(R.drawable.panel\_search);  
                iv3.setImageResource(R.drawable.panel\_menu);  
                iv4.setImageResource(R.drawable.panel\_home);  
            }else{  
                Log.i("orie", "port");  
                setOrientation(LinearLayout.HORIZONTAL);  
                iv1.setImageResource(R.drawable.panel\_home);  
                iv2.setImageResource(R.drawable.panel\_menu);  
                iv3.setImageResource(R.drawable.panel\_search);  
                iv4.setImageResource(R.drawable.panel\_back);  
            }  
        }  
        Log.i("orie", "executed");  
        super.onConfigurationChanged(newConfig);  
    }  
}