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. Javascript 选项卡

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  2. utmp, wtmp, and lastlog 日志清除工具

    utmp, wtmp, and lastlog 日志清除工具 http://blog.itpub.net/83980/viewspace-801664/

  3. PHP图标类库 - JpGraph使用详解

    http://w3note.com/web/181.html 微信平台开发的推广支持应用里,为了满足用户渠道推广分析的需要,公众平台提供了生成带参数二维码的接口.使用该接口可以获得多个带不同场景值的二 ...

  4. 用DateTime.ToString(string format)输出不同格式的日期

    http://www.cnblogs.com/xvqm00/archive/2009/02/19/1394093.html DateTime.ToString()函数有四个重载.一般用得多的就是不带参 ...

  5. Nhibernate

    Nhibernate入门与demo 学习和使用Nhibernate已经很久了,一直想写点东西和大家一起学习使用Nhibernate.博客园里也有很多大牛写了很多关于Nhibernate入门的文章.其中 ...

  6. MIT算法导论——第五讲.Linear Time Sort

    本栏目(Algorithms)下MIT算法导论专题是个人对网易公开课MIT算法导论的学习心得与笔记.所有内容均来自MIT公开课Introduction to Algorithms中Charles E. ...

  7. 2014-9-17二班----9 web project

    http://localhost:8080/rwkj1/indexServlet             跳转                    http://localhost:8080/rwk ...

  8. Photoshop:制作金属质感-不锈钢纹理

    效果图 过程: 1.滤镜->渲染->云彩 2.滤镜->模糊->高斯模糊 3.滤镜->杂色->添加杂色 ,数量10 4.滤镜->模糊->径向模糊 5.滤镜 ...

  9. iOS 精确定时器

    Do I need a high precision timer? Don't use a high precision timer unless you really need it. They c ...

  10. 246. Strobogrammatic Number

    题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at ups ...