android:allowSingleTap   指示抽屉是否可以打开/通过手柄上的一个水龙头关闭。

android:animateOnClick  表示所述抽屉是否应该打开/与当用户点击手柄动画关闭。      

android:bottomOffset     额外偏移的把手在SlidingDrawer的底部。
android:content   标识符表示抽屉的内容孩子。

Identifier for the child that represents the drawer's content. 
android:handle     标识符表示抽屉的把手的孩子。

Identifier for the child that represents the drawer's handle.
android:orientation

Orientation of the SlidingDrawer.  取向SlidingDrawer的。
android:topOffset

Extra offset for the handle at the top of the SlidingDrawer.

额外偏移的把手在SlidingDrawer的顶部。

 import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SlidingDrawer; /**
* 使得SlidingDrawer在屏幕低端,而不会填满整个屏幕
*/
public class WrapSlidingDrawer extends SlidingDrawer { private boolean mVertical;
private int mTopOffset; // 从指定的XML定义的属性集创建一个新的WrapSlidingDrawer。
public WrapSlidingDrawer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
/**
* namespace 属性的命名空间来获取。
* attribute 属性检索。
* defaultValue 如果未找到该属性返回什么。
*
* ORIENTATION_VERTICAL:定向垂直。
*/
int orientation = attrs.getAttributeIntValue("android", "orientation",
ORIENTATION_VERTICAL);
// "topOffset" 额外偏移的把手在SlidingDrawer的顶部。
mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
} public WrapSlidingDrawer(Context context, AttributeSet attrs) {
super(context, attrs);
int orientation = attrs.getAttributeIntValue("android", "orientation",
ORIENTATION_VERTICAL);
mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
} /**
* 测量视图和其内容,以确定所测量的宽度和所测量的高度。
* widthMeasureSpec 宽度测量规格。
* heightMeasureSpec 高度测量规格。
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
// 返回抽屉的手柄。
final View handle = getHandle();
// 返回抽屉的内容。
final View content = getContent();
/**
* Ask one of the children of this view to measure itself, taking into
* account both the MeasureSpec requirements for this view and its padding.
* The heavy lifting is done in getChildMeasureSpec.
*
* @param child The child to measure
* @param parentWidthMeasureSpec The width requirements for this view
* @param parentHeightMeasureSpec The height requirements for this view
*/
measureChild(handle, widthMeasureSpec, heightMeasureSpec); if (mVertical) {
// 测量高度 - 抽屉手柄高度 - 额外偏移的把手顶部
int height = heightSpecSize - handle.getMeasuredHeight()
- mTopOffset;
// 内容尺寸
// public static int makeMeasureSpec (int size, int mode)
// Creates a measure specification based on the supplied size and mode.
// size the size of the measure specification
// mode the mode of the measure specification
content.measure(widthMeasureSpec,
MeasureSpec.makeMeasureSpec(height, heightSpecMode));
//
heightSpecSize = handle.getMeasuredHeight() + mTopOffset
+ content.getMeasuredHeight();
//
widthSpecSize = content.getMeasuredWidth();
//
if (handle.getMeasuredWidth() > widthSpecSize)
widthSpecSize = handle.getMeasuredWidth();
} else {
int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
getContent().measure(
MeasureSpec.makeMeasureSpec(width, widthSpecMode),
heightMeasureSpec);
widthSpecSize = handle.getMeasuredWidth() + mTopOffset
+ content.getMeasuredWidth();
heightSpecSize = content.getMeasuredHeight();
if (handle.getMeasuredHeight() > heightSpecSize)
heightSpecSize = handle.getMeasuredHeight();
}
// 此方法必须由onMeasure(int,int)被调用储存的测量宽度和高度测量。
setMeasuredDimension(widthSpecSize, heightSpecSize);
}
}
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <TextView
android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:gravity="center"
android:text="AAAAAAAAAAAAAA"
android:textSize="10pt" /> <com.cn.daming.WrapSlidingDrawer
android:id="@+id/sliding_drawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:content="@+id/mycontent"
android:handle="@+id/layout1"
android:layout_alignParentBottom="true"
android:orientation="vertical" > <LinearLayout
android:id="@id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center" > <ImageView
android:id="@+id/my_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/up1" />
</LinearLayout> <GridView
android:id="@id/mycontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff000000"
android:gravity="center"
android:numColumns="3"
android:paddingTop="20dip" />
</com.cn.daming.WrapSlidingDrawer> </RelativeLayout>

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SlidingDrawer;
import android.widget.TextView; public class SlidingDrawerMainActivity extends Activity { private GridView gridView;
private SlidingDrawer slidingDrawer;
private ImageView imageView;
private TextView textview;
private int[] icons = { R.drawable.title1, R.drawable.title2,
R.drawable.title3, R.drawable.title4, R.drawable.title5,
R.drawable.title6 }; private String[] items = { "Phone", "Message", "AddImage", "Music",
"Telephone", "SMS" }; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.main); gridView = (GridView) findViewById(R.id.mycontent);
slidingDrawer = (SlidingDrawer) findViewById(R.id.sliding_drawer);
imageView = (ImageView) findViewById(R.id.my_image);
textview = (TextView) findViewById(R.id.text_view);
MyGridViewAdapter adapter = new MyGridViewAdapter(this, items, icons);
gridView.setAdapter(adapter); slidingDrawer
.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() { public void onDrawerOpened() {
textview.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.down1);
}
});
slidingDrawer
.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() { public void onDrawerClosed() {
textview.setVisibility(View.VISIBLE);
imageView.setImageResource(R.drawable.up1);
}
});
} @Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
}

完整代码下载:http://pan.baidu.com/s/1sjsdqTv

自定义控件:抽屉SlidingDrawer——wrap_content非全屏的更多相关文章

  1. OSG 初始化为非全屏窗口

    OSG默认的窗口时全屏的,调试的时候不方便. 在网上看到一段代码,可以非全屏显示 int _tmain(int argc, _TCHAR* argv[]){ osgViewer::Viewer vie ...

  2. 微信非全屏播放设置(仅Iphone)

    由于微信X5内核强制视频全屏,用X5自带内核播放,一般内嵌视频打开播放就会被全屏. ihpone里面可以通过设置 x-webkit-airplay="true" webkit-pl ...

  3. IOS(苹果手机)使用video播放HLS流,实现在内部播放及全屏播放(即非全屏和全屏播放)。

    需求: 实现PC及移动端播放HLS流,并且可以自动播放,在页面内部播放及全屏播放功能. 初步:PC及安卓机使用hls.js实现hls流自动播放及全屏非全屏播放 首先使用了hls.js插件,可以实现在P ...

  4. 为cocos2d-x实现安卓输入框。非全屏,无dialog,绑定到lua

    cocos2d-x官方自带的输入框,简直惨不忍睹,在ios还好,在安卓简直了..用过的都知道... 所以为了用户体验,我们自己搞一个吧.输入框这种东西比较特殊,不像按钮.列表框之类的很容易实现,因为涉 ...

  5. 【Win 10应用开发】实现全屏播放的方法

    有人会问,以前的MediaElement控件不是有现成的一排操作按钮吗?而且可以直接进入全屏播放.是的,我们知道,以往的Store App都是在全屏模式下运行的,只要MediaElement控件填满整 ...

  6. VirtualBox全屏切换

    用VirtualBox的时候,如果设置为全屏,想再切换回来,没有什么菜单,只有通过键盘的快捷键来操作,才可以恢复. 我常常忘掉,所以老是得去找,以后需要记住这几个按键的快捷键. 1.全屏与非全屏切换: ...

  7. 如何制作一个完美的全屏视频H5

    写在前面的话: 最近一波H5广告火爆整个互联网圈,身为圈内人,我们怎能     不! 知!道! :( 嘘!真不知道的也继续看下去,有收获 ↓ ) So,搞懂这个并不难. 这篇文章将带你从头到尾了解H5 ...

  8. JS 取消iOS播放自动全屏:

    iOS下浏览器模式下h5播放器强制是全屏的,除非在app下才可以非全屏播放,需要两个配置: (1)播放器添加参数: playsinline:true(我使用的是阿里云的播放器,其他的需要自己找找是那个 ...

  9. C# WinForm 关于窗体最大化时的是否全屏效果与是否遮盖任务栏

    0.新建窗体 及添加按钮 1.  执行如下按钮事件  private void btnFormMax_Click(object sender, EventArgs e)  {     if (this ...

随机推荐

  1. java基础知识回顾之java Thread类学习(三)--java线程实现常见的两种方式实现好处:

    总结:实现Runnable接口比继承Thread类更有优势: 1.因为java只能单继承,实现Runnable接口可以避免单继承的局限性 2.继承Thread类,多个线程不能处理或者共享同一个资源,但 ...

  2. ElasticSearch Java api 详解_V1.0

    /×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...

  3. 查杀linux线程指令

      工作中重启环境时常常出现内存溢出等等问题,往往需要查杀进程来帮助重启成功,下面就查杀线程的详细指令做下总结:   1.查找需要kill掉的线程: ps -elf|grep [线程关键信息] 比如: ...

  4. CF 221div2 A. Lever

    A. Lever 题目:http://codeforces.com/contest/376/problem/A 题意:杠杆原理 比两边的重量 input =^== output balance 9== ...

  5. ActiveMQ 学习笔记

    http://somebody-hjh.iteye.com/blog/726050 一.概述 Message,即消息.人与人之间通过消息传递信息.言语.眼神.肢体动作都可被视为消息体.当然还有我们经常 ...

  6. js call apply bind简单的理解

    相同点:JS中call与apply方法可以改变某个函数执行的上下文环境,也就是可以改变函数内this的指向.区别:call与apply方法的参数中,第一个参数都是指定的上下文环境或者指定的对象,而ca ...

  7. BZOJ 3720 gty的妹子树

    块状树裸题 块状树: 首先对树进行分块,分出的每一块都是一个连通块 通常的分块的方式如下: 1.父亲所在块不满,分到父亲所在块中 2.父亲所在块满,自己单独开一个块 (貌似有更为优越的分块方式? 注意 ...

  8. 再谈PCA

        其实之前写过PCA相关的博文,但是由于之前掌握的理论知识有限,所以理解也比较浅.这篇博文,我们以另外一种角度来理解PCA看,这里我假设大家对PCA都有一个初步的了解.首先,我们举一个二维空间中 ...

  9. 【nginx运维基础(7)】常用PHP开源程序的NginxRewrite示例

    在写伪静态的时候,可以先用一个打印$_GET的PHP文件来测试,并且一定注意浏览器缓存,另外正则里如果有"{}",正则要用双引号包起来 dedecms location / { r ...

  10. eclipse安装反编译插件

    1. 进入http://jadclipse.sourceforge.net/wiki/index.php/Main_Page#Download          下载 net.sf.jadclipse ...