Android中使用系统桌面背景作为应用背景,支持拖动

在Android应用开发中,使用系统桌面背景作为应用的背景,需要把应用的背景设置为透明背景,然后设置窗口的属性为FLAG_SHOW_WALLPAPER即可显示背景。

修改AndroidManifest.xml文件里面activity属性:

 

        <activity android:name=".WallPaperTest"

                  android:label="@string/app_name"

                  android:theme="@android:style/Theme.Translucent">

然后在使用的时候,在onCreate里面添加一个窗口属性

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);

 

在背景拖动的时候主要是使用了WallpaperManager这个类的两个方法

 

public void setWallpaperOffsetSteps (float xStep, float yStep)
Since:  API Level 7

For applications that use multiple virtual screens showing a wallpaper, specify the step size between virtual screens. For example, if the launcher has 3 virtual screens, it would specify an xStep of 0.5, since the X offset for those screens are 0.0, 0.5 and 1.0

Parameters
xStepThe X offset delta from one screen to the next one
yStepThe Y offset delta from one screen to the next one

public void setWallpaperOffsets (IBinder windowToken, float xOffset, float yOffset)
Since:  API Level 5

Set the position of the current wallpaper within any larger space, when that wallpaper is visible behind the given window. The X and Y offsets are floating point numbers ranging from 0 to 1, representing where the wallpaper should be positioned within the screen space. These only make sense when the wallpaper is larger than the screen.

Parameters
windowTokenThe window who these offsets should be associated with, as returned by View.getWindowToken().
xOffsetThe offset along the X dimension, from 0 to 1.
yOffset

The offset along the Y dimension, from 0 to 1.

 

修改了之前ScrollLayout的类,让它支持显示系统背景,并且拖动的时候背景也跟着拖动,跟Launcher中的效果一致。。。
基本类文件ScrollLayout.java
  1. package com.yao_guet;  
  2. import android.app.WallpaperManager;  
  3. import android.content.Context;  
  4. import android.os.IBinder;  
  5. import android.util.AttributeSet;  
  6. import android.util.Log;  
  7. import android.view.MotionEvent;  
  8. import android.view.VelocityTracker;  
  9. import android.view.View;  
  10. import android.view.ViewConfiguration;  
  11. import android.view.ViewGroup;  
  12. import android.widget.Scroller;  
  13. /** 
  14.  * 仿Launcher中的WorkSapce,可以左右滑动切换屏幕的类,支持显示系统背景和滑动 
  15.  * @author Yao.GUET 
  16.  * blog: http://blog.csdn.net/Yao_GUET 
  17.  * date: 2011-05-04 
  18.  */  
  19. public class ScrollLayout extends ViewGroup {  
  20.     private static final String TAG = "ScrollLayout";  
  21.     private Scroller mScroller;  
  22.     private VelocityTracker mVelocityTracker;  
  23.       
  24.     private int mCurScreen;  
  25.     private int mDefaultScreen = 0;  
  26.       
  27.     private static final int TOUCH_STATE_REST = 0;  
  28.     private static final int TOUCH_STATE_SCROLLING = 1;  
  29.       
  30.     private static final int SNAP_VELOCITY = 600;  
  31.       
  32.     private int mTouchState = TOUCH_STATE_REST;  
  33.     private int mTouchSlop;  
  34.     private float mLastMotionX;  
  35.     private float mLastMotionY;  
  36.       
  37.     private WallpaperManager mWallpaperManager;  
  38.     private int mScrollX;  
  39.     public ScrollLayout(Context context, AttributeSet attrs) {  
  40.         this(context, attrs, 0);  
  41.         // TODO Auto-generated constructor stub   
  42.     }  
  43.     public ScrollLayout(Context context, AttributeSet attrs, int defStyle) {  
  44.         super(context, attrs, defStyle);  
  45.         // TODO Auto-generated constructor stub   
  46.           
  47.         mWallpaperManager = WallpaperManager.getInstance(context);  
  48.         mScroller = new Scroller(context);  
  49.           
  50.         mCurScreen = mDefaultScreen;  
  51.         mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();  
  52.     }  
  53.     @Override  
  54.     protected void onLayout(boolean changed, int l, int t, int r, int b) {  
  55.         // TODO Auto-generated method stub   
  56.         Log.e(TAG, "onLayout");  
  57.         int childLeft = 0;  
  58.         final int childCount = getChildCount();  
  59.           
  60.         for (int i=0; i<childCount; i++) {  
  61.             final View childView = getChildAt(i);  
  62.             if (childView.getVisibility() != View.GONE) {  
  63.                 final int childWidth = childView.getMeasuredWidth();  
  64.                 childView.layout(childLeft, 0,   
  65.                         childLeft+childWidth, childView.getMeasuredHeight());  
  66.                 childLeft += childWidth;  
  67.             }  
  68.         }  
  69.         updateWallpaperOffset();  
  70.     }  
  71.   
  72.     @Override    
  73.     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {     
  74.         Log.e(TAG, "onMeasure");  
  75.         super.onMeasure(widthMeasureSpec, heightMeasureSpec);     
  76.     
  77.         final int width = MeasureSpec.getSize(widthMeasureSpec);     
  78.         final int widthMode = MeasureSpec.getMode(widthMeasureSpec);     
  79.         if (widthMode != MeasureSpec.EXACTLY) {     
  80.             throw new IllegalStateException("ScrollLayout only canmCurScreen run at EXACTLY mode!");   
  81.         }     
  82.     
  83.         final int heightMode = MeasureSpec.getMode(heightMeasureSpec);     
  84.         if (heightMode != MeasureSpec.EXACTLY) {     
  85.             throw new IllegalStateException("ScrollLayout only can run at EXACTLY mode!");  
  86.         }     
  87.     
  88.         // The children are given the same width and height as the scrollLayout      
  89.         final int count = getChildCount();     
  90.         for (int i = 0; i < count; i++) {     
  91.             getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);     
  92.         }     
  93.         // Log.e(TAG, "moving to screen "+mCurScreen);      
  94.         scrollTo(mCurScreen * width, 0);           
  95.     }    
  96.       
  97.     /** 
  98.      * According to the position of current layout 
  99.      * scroll to the destination page. 
  100.      */  
  101.     public void snapToDestination() {  
  102.         final int screenWidth = getWidth();  
  103.         final int destScreen = (getScrollX()+ screenWidth/2)/screenWidth;  
  104.         snapToScreen(destScreen);  
  105.     }  
  106.       
  107.     public void snapToScreen(int whichScreen) {  
  108.         // get the valid layout page   
  109.         whichScreen = Math.max(0, Math.min(whichScreen, getChildCount()-1));  
  110.         if (getScrollX() != (whichScreen*getWidth())) {  
  111.               
  112.             final int delta = whichScreen*getWidth()-getScrollX();  
  113.             mScroller.startScroll(getScrollX(), 0,   
  114.                     delta, 0, Math.abs(delta)*2);  
  115.             mCurScreen = whichScreen;  
  116.             invalidate();       // Redraw the layout   
  117.         }  
  118.     }  
  119.       
  120.     public void setToScreen(int whichScreen) {  
  121.         whichScreen = Math.max(0, Math.min(whichScreen, getChildCount()-1));  
  122.         mCurScreen = whichScreen;  
  123.         scrollTo(whichScreen*getWidth(), 0);  
  124.     }  
  125.       
  126.     public int getCurScreen() {  
  127.         return mCurScreen;  
  128.     }  
  129.       
  130.     @Override  
  131.     public void computeScroll() {  
  132.         // TODO Auto-generated method stub   
  133.         mScrollX = mScroller.getCurrX();  
  134.         if (mScroller.computeScrollOffset()) {  
  135.             scrollTo(mScroller.getCurrX(), mScroller.getCurrY());  
  136.             updateWallpaperOffset();  
  137.               
  138.             postInvalidate();  
  139.         }  
  140.     }  
  141.     @Override  
  142.     public boolean onTouchEvent(MotionEvent event) {  
  143.         // TODO Auto-generated method stub   
  144.           
  145.         if (mVelocityTracker == null) {  
  146.             mVelocityTracker = VelocityTracker.obtain();  
  147.         }  
  148.         mVelocityTracker.addMovement(event);  
  149.           
  150.         final int action = event.getAction();  
  151.         final float x = event.getX();  
  152.         final float y = event.getY();  
  153.           
  154.         switch (action) {  
  155.         case MotionEvent.ACTION_DOWN:  
  156.             Log.e(TAG, "event down!");  
  157.             if (!mScroller.isFinished()){  
  158.                 mScroller.abortAnimation();  
  159.             }  
  160.             mLastMotionX = x;  
  161.             break;  
  162.               
  163.         case MotionEvent.ACTION_MOVE:  
  164.             int deltaX = (int)(mLastMotionX - x);  
  165.             mLastMotionX = x;  
  166.             scrollBy(deltaX, 0);  
  167.             updateWallpaperOffset();  
  168.             break;  
  169.               
  170.         case MotionEvent.ACTION_UP:  
  171.             Log.e(TAG, "event : up");     
  172.             // if (mTouchState == TOUCH_STATE_SCROLLING) {      
  173.             final VelocityTracker velocityTracker = mVelocityTracker;     
  174.             velocityTracker.computeCurrentVelocity(1000);     
  175.             int velocityX = (int) velocityTracker.getXVelocity();     
  176.             Log.e(TAG, "velocityX:"+velocityX);   
  177.               
  178.             if (velocityX > SNAP_VELOCITY && mCurScreen > 0) {     
  179.                 // Fling enough to move left      
  180.                 Log.e(TAG, "snap left");  
  181.                 snapToScreen(mCurScreen - 1);     
  182.             } else if (velocityX < -SNAP_VELOCITY     
  183.                     && mCurScreen < getChildCount() - 1) {     
  184.                 // Fling enough to move right      
  185.                 Log.e(TAG, "snap right");  
  186.                 snapToScreen(mCurScreen + 1);     
  187.             } else {     
  188.                 snapToDestination();     
  189.             }     
  190.             if (mVelocityTracker != null) {     
  191.                 mVelocityTracker.recycle();     
  192.                 mVelocityTracker = null;     
  193.             }     
  194.             // }      
  195.             mTouchState = TOUCH_STATE_REST;     
  196.             break;  
  197.         case MotionEvent.ACTION_CANCEL:  
  198.             mTouchState = TOUCH_STATE_REST;  
  199.             break;  
  200.         }  
  201.           
  202.         return true;  
  203.     }  
  204.     @Override  
  205.     public boolean onInterceptTouchEvent(MotionEvent ev) {  
  206.         // TODO Auto-generated method stub   
  207.         Log.e(TAG, "onInterceptTouchEvent-slop:"+mTouchSlop);  
  208.           
  209.         final int action = ev.getAction();  
  210.         if ((action == MotionEvent.ACTION_MOVE) &&   
  211.                 (mTouchState != TOUCH_STATE_REST)) {  
  212.             return true;  
  213.         }  
  214.           
  215.         final float x = ev.getX();  
  216.         final float y = ev.getY();  
  217.           
  218.         switch (action) {  
  219.         case MotionEvent.ACTION_MOVE:  
  220.             final int xDiff = (int)Math.abs(mLastMotionX-x);  
  221.             if (xDiff>mTouchSlop) {  
  222.                 mTouchState = TOUCH_STATE_SCROLLING;  
  223.                   
  224.             }  
  225.             break;  
  226.               
  227.         case MotionEvent.ACTION_DOWN:  
  228.             mLastMotionX = x;  
  229.             mLastMotionY = y;  
  230.             mTouchState = mScroller.isFinished()? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;  
  231.             break;  
  232.               
  233.         case MotionEvent.ACTION_CANCEL:  
  234.         case MotionEvent.ACTION_UP:  
  235.             mTouchState = TOUCH_STATE_REST;  
  236.             break;  
  237.         }  
  238.           
  239.         return mTouchState != TOUCH_STATE_REST;  
  240.     }  
  241.       
  242.       
  243.     private void updateWallpaperOffset() {  
  244.         int scrollRange = getChildAt(getChildCount() - 1).getRight() - getWidth();  
  245.         IBinder token = getWindowToken();  
  246.         if (token != null) {  
  247.             mWallpaperManager.setWallpaperOffsetSteps(1.0f / (getChildCount() - 1), 0 );  
  248.             mWallpaperManager.setWallpaperOffsets(getWindowToken(),  
  249.                     Math.max(0.f, Math.min(getScrollX()/(float)scrollRange, 1.f)), 0);  
  250.         }  
  251.     }  
  252. }  
package com.yao_guet;
import android.app.WallpaperManager;
import android.content.Context;
import android.os.IBinder;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.Scroller;
/**
 * 仿Launcher中的WorkSapce,可以左右滑动切换屏幕的类,支持显示系统背景和滑动
 * @author Yao.GUET
 * blog: http://blog.csdn.net/Yao_GUET
 * date: 2011-05-04
 */
public class ScrollLayout extends ViewGroup {
	private static final String TAG = "ScrollLayout";
	private Scroller mScroller;
	private VelocityTracker mVelocityTracker;
	
	private int mCurScreen;
	private int mDefaultScreen = 0;
	
	private static final int TOUCH_STATE_REST = 0;
	private static final int TOUCH_STATE_SCROLLING = 1;
	
	private static final int SNAP_VELOCITY = 600;
	
	private int mTouchState = TOUCH_STATE_REST;
	private int mTouchSlop;
	private float mLastMotionX;
	private float mLastMotionY;
	
	private WallpaperManager mWallpaperManager;
	private int mScrollX;
	public ScrollLayout(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
		// TODO Auto-generated constructor stub
	}
	public ScrollLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		
		mWallpaperManager = WallpaperManager.getInstance(context);
		mScroller = new Scroller(context);
		
		mCurScreen = mDefaultScreen;
		mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
	}
	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		// TODO Auto-generated method stub
		Log.e(TAG, "onLayout");
		int childLeft = 0;
		final int childCount = getChildCount();
		
		for (int i=0; i<childCount; i++) {
			final View childView = getChildAt(i);
			if (childView.getVisibility() != View.GONE) {
				final int childWidth = childView.getMeasuredWidth();
				childView.layout(childLeft, 0, 
						childLeft+childWidth, childView.getMeasuredHeight());
				childLeft += childWidth;
			}
		}
		updateWallpaperOffset();
	}

    @Override  
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {   
    	Log.e(TAG, "onMeasure");
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);   
  
        final int width = MeasureSpec.getSize(widthMeasureSpec);   
        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);   
        if (widthMode != MeasureSpec.EXACTLY) {   
            throw new IllegalStateException("ScrollLayout only canmCurScreen run at EXACTLY mode!"); 
        }   
  
        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);   
        if (heightMode != MeasureSpec.EXACTLY) {   
            throw new IllegalStateException("ScrollLayout only can run at EXACTLY mode!");
        }   
  
        // The children are given the same width and height as the scrollLayout   
        final int count = getChildCount();   
        for (int i = 0; i < count; i++) {   
            getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);   
        }   
        // Log.e(TAG, "moving to screen "+mCurScreen);   
        scrollTo(mCurScreen * width, 0);         
    }  
    
    /**
     * According to the position of current layout
     * scroll to the destination page.
     */
    public void snapToDestination() {
    	final int screenWidth = getWidth();
    	final int destScreen = (getScrollX()+ screenWidth/2)/screenWidth;
    	snapToScreen(destScreen);
    }
    
    public void snapToScreen(int whichScreen) {
    	// get the valid layout page
    	whichScreen = Math.max(0, Math.min(whichScreen, getChildCount()-1));
    	if (getScrollX() != (whichScreen*getWidth())) {
    		
    		final int delta = whichScreen*getWidth()-getScrollX();
    		mScroller.startScroll(getScrollX(), 0, 
    				delta, 0, Math.abs(delta)*2);
    		mCurScreen = whichScreen;
    		invalidate();		// Redraw the layout
    	}
    }
    
    public void setToScreen(int whichScreen) {
    	whichScreen = Math.max(0, Math.min(whichScreen, getChildCount()-1));
    	mCurScreen = whichScreen;
    	scrollTo(whichScreen*getWidth(), 0);
    }
    
    public int getCurScreen() {
    	return mCurScreen;
    }
    
	@Override
	public void computeScroll() {
		// TODO Auto-generated method stub
		mScrollX = mScroller.getCurrX();
		if (mScroller.computeScrollOffset()) {
			scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
			updateWallpaperOffset();
			
			postInvalidate();
		}
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		
		if (mVelocityTracker == null) {
			mVelocityTracker = VelocityTracker.obtain();
		}
		mVelocityTracker.addMovement(event);
		
		final int action = event.getAction();
		final float x = event.getX();
		final float y = event.getY();
		
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			Log.e(TAG, "event down!");
			if (!mScroller.isFinished()){
				mScroller.abortAnimation();
			}
			mLastMotionX = x;
			break;
			
		case MotionEvent.ACTION_MOVE:
			int deltaX = (int)(mLastMotionX - x);
			mLastMotionX = x;
            scrollBy(deltaX, 0);
            updateWallpaperOffset();
			break;
			
		case MotionEvent.ACTION_UP:
			Log.e(TAG, "event : up");   
            // if (mTouchState == TOUCH_STATE_SCROLLING) {   
            final VelocityTracker velocityTracker = mVelocityTracker;   
            velocityTracker.computeCurrentVelocity(1000);   
            int velocityX = (int) velocityTracker.getXVelocity();   
            Log.e(TAG, "velocityX:"+velocityX); 
            
            if (velocityX > SNAP_VELOCITY && mCurScreen > 0) {   
                // Fling enough to move left   
            	Log.e(TAG, "snap left");
                snapToScreen(mCurScreen - 1);   
            } else if (velocityX < -SNAP_VELOCITY   
                    && mCurScreen < getChildCount() - 1) {   
                // Fling enough to move right   
            	Log.e(TAG, "snap right");
                snapToScreen(mCurScreen + 1);   
            } else {   
                snapToDestination();   
            }   
            if (mVelocityTracker != null) {   
                mVelocityTracker.recycle();   
                mVelocityTracker = null;   
            }   
            // }   
            mTouchState = TOUCH_STATE_REST;   
			break;
		case MotionEvent.ACTION_CANCEL:
			mTouchState = TOUCH_STATE_REST;
			break;
		}
		
		return true;
	}
	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		// TODO Auto-generated method stub
		Log.e(TAG, "onInterceptTouchEvent-slop:"+mTouchSlop);
		
		final int action = ev.getAction();
		if ((action == MotionEvent.ACTION_MOVE) && 
				(mTouchState != TOUCH_STATE_REST)) {
			return true;
		}
		
		final float x = ev.getX();
		final float y = ev.getY();
		
		switch (action) {
		case MotionEvent.ACTION_MOVE:
			final int xDiff = (int)Math.abs(mLastMotionX-x);
			if (xDiff>mTouchSlop) {
				mTouchState = TOUCH_STATE_SCROLLING;
				
			}
			break;
			
		case MotionEvent.ACTION_DOWN:
			mLastMotionX = x;
			mLastMotionY = y;
			mTouchState = mScroller.isFinished()? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
			break;
			
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			mTouchState = TOUCH_STATE_REST;
			break;
		}
		
		return mTouchState != TOUCH_STATE_REST;
	}
	
	
	private void updateWallpaperOffset() {
        int scrollRange = getChildAt(getChildCount() - 1).getRight() - getWidth();
        IBinder token = getWindowToken();
        if (token != null) {
            mWallpaperManager.setWallpaperOffsetSteps(1.0f / (getChildCount() - 1), 0 );
            mWallpaperManager.setWallpaperOffsets(getWindowToken(),
                    Math.max(0.f, Math.min(getScrollX()/(float)scrollRange, 1.f)), 0);
        }
    }
}


测试代码WallPaperTest.java:
  1. package com.yao_guet;  
  2. import android.app.Activity;  
  3. import android.app.WallpaperManager;  
  4. import android.content.Context;  
  5. import android.os.Bundle;  
  6. import android.view.KeyEvent;  
  7. import android.view.Window;  
  8. import android.view.WindowManager;  
  9. public class WallPaperTest extends Activity {  
  10.     @Override  
  11.     protected void onCreate(Bundle savedInstanceState) {  
  12.         // TODO Auto-generated method stub   
  13.         super.onCreate(savedInstanceState);  
  14.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
  15.         setContentView(R.layout.wallpaper_test);  
  16.         getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);  
  17.     }  
  18.     @Override  
  19.     protected void onDestroy() {  
  20.         // TODO Auto-generated method stub   
  21.         super.onDestroy();  
  22.     }  
  23.     @Override  
  24.     public boolean onKeyDown(int keyCode, KeyEvent event) {  
  25.         // TODO Auto-generated method stub   
  26.         return super.onKeyDown(keyCode, event);  
  27.     }  
  28. }  
package com.yao_guet;
import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
public class WallPaperTest extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.wallpaper_test);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
	}
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		return super.onKeyDown(keyCode, event);
	}
}


layout布局文件wallpaper_test.xml:
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <com.sf.test.ScrollLayout  
  3.   xmlns:android="http://schemas.android.com/apk/res/android"  
  4.   android:id="@+id/WallPaperTest"  
  5.   android:layout_width="fill_parent"  
  6.   android:layout_height="fill_parent">  
  7. <LinearLayout  
  8.   android:layout_width="fill_parent"  
  9.   android:layout_height="fill_parent">  
  10.   <TextView  
  11.     android:layout_width="fill_parent"  
  12.     android:layout_height="wrap_content"  
  13.     android:text="This is page 1" />  
  14.   </LinearLayout>  
  15.     
  16. <LinearLayout  
  17.   android:layout_width="fill_parent"  
  18.   android:layout_height="fill_parent">  
  19.   <TextView  
  20.     android:layout_width="fill_parent"  
  21.     android:layout_height="wrap_content"  
  22.     android:text="This is page 2" />  
  23.   </LinearLayout>  
  24.     
  25. <LinearLayout  
  26.   android:layout_width="fill_parent"  
  27.   android:layout_height="fill_parent">  
  28.   <TextView  
  29.     android:layout_width="fill_parent"  
  30.     android:layout_height="wrap_content"  
  31.     android:text="This is page 3" />  
  32.   </LinearLayout>  
  33.     
  34. <LinearLayout  
  35.   android:layout_width="fill_parent"  
  36.   android:layout_height="fill_parent">  
  37.   <TextView  
  38.     android:layout_width="fill_parent"  
  39.     android:layout_height="wrap_content"  
  40.     android:text="This is page 4" />  
  41.   </LinearLayout>  
  42. <LinearLayout  
  43.   android:layout_width="fill_parent"  
  44.   android:layout_height="fill_parent">  
  45.   <TextView  
  46.     android:layout_width="fill_parent"  
  47.     android:layout_height="wrap_content"  
  48.     android:text="This is page 5" />  
  49.   </LinearLayout>  
  50. <LinearLayout  
  51.   android:layout_width="fill_parent"  
  52.   android:layout_height="fill_parent">  
  53.   <TextView  
  54.     android:layout_width="fill_parent"  
  55.     android:layout_height="wrap_content"  
  56.     android:text="This is page 6" />  
  57.   </LinearLayout>  
  58.     
  59. <LinearLayout  
  60.   android:layout_width="fill_parent"  
  61.   android:layout_height="fill_parent">  
  62.   <TextView  
  63.     android:layout_width="fill_parent"  
  64.     android:layout_height="wrap_content"  
  65.     android:text="This is page 7" />  
  66.   </LinearLayout>  
  67. </com.sf.test.ScrollLayout>  
<?xml version="1.0" encoding="utf-8"?>
<com.sf.test.ScrollLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/WallPaperTest"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView
  	android:layout_width="fill_parent"
  	android:layout_height="wrap_content"
  	android:text="This is page 1" />
  </LinearLayout>
  
<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView
  	android:layout_width="fill_parent"
  	android:layout_height="wrap_content"
  	android:text="This is page 2" />
  </LinearLayout>
  
<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView
  	android:layout_width="fill_parent"
  	android:layout_height="wrap_content"
  	android:text="This is page 3" />
  </LinearLayout>
  
<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView
  	android:layout_width="fill_parent"
  	android:layout_height="wrap_content"
  	android:text="This is page 4" />
  </LinearLayout>
<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView
  	android:layout_width="fill_parent"
  	android:layout_height="wrap_content"
  	android:text="This is page 5" />
  </LinearLayout>
<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView
  	android:layout_width="fill_parent"
  	android:layout_height="wrap_content"
  	android:text="This is page 6" />
  </LinearLayout>
  
<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView
  	android:layout_width="fill_parent"
  	android:layout_height="wrap_content"
  	android:text="This is page 7" />
  </LinearLayout>
</com.sf.test.ScrollLayout>


然后记得修改AndroidManifest.xml文件。。。

        <activity android:name=".WallPaperTest"

                  android:label="@string/app_name"

                  android:theme="@android:style/Theme.Translucent">

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值