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. HDU 3501 Calculation 2 (欧拉函数)

    题目链接 题意 : 求小于n的数中与n不互质的所有数字之和. 思路 : 欧拉函数求的是小于等于n的数中与n互质的数个数,这个题的话,先把所有的数字之和求出来,再减掉欧拉函数中所有质数之和(即为eula ...

  2. 通过快捷键及cmd命令注销系统

    公司的外网内网是隔离的 外网的远程电脑屏幕一半卡那了,页面注销键正好在卡死的那一半屏幕上,用以下简单方法注销远程重新连接,问题解决了. 1.通过快捷键win+r打开“运行...” 2.输入CMD 回车 ...

  3. H5 移动Web框架集合

    http://frozenui.github.io/  一个简洁的h5前端框架 http://weui.github.io/weui/ 腾讯出的WebUI 风格是基于微信

  4. 深入浅出Java并发包—锁机制(一)

    前面我们看到了Lock和synchronized都能正常的保证数据的一致性(上文例子中执行的结果都是20000000),也看到了Lock的优势,那究竟他们是什么原理来保障的呢?今天我们就来探讨下Jav ...

  5. HorseCome

    紫气东来,祝福也随之而来,喜鹊登梅,福禄也登上眉梢,马年将至,喜庆将萦绕身旁,在这个美好的日子送上我最真挚的祝福,祝身体安康. 春晓,春晓,处处绿杨芳草.山山水水,欢欢笑笑,共祝六合同春,步步登高!

  6. *Linux之rm命令

    自己瞅: [root@winner ~]# rm --help//rm-->remove用法:rm [选项]... 文件... 删除 (unlink) 文件. -f, --force 强制删除. ...

  7. 31. Next Permutation

    题目: Implement next permutation, which rearranges numbers into the lexicographically next greater per ...

  8. grunt + compass retina sprites

    https://github.com/AdamBrodzinski/Retina-Sprites-for-Compass

  9. 百度HTTPS加密搜索有什么用?

    前段时间,我曾提到百度支持移动端HTTPS SSL加密搜索,用以保护用户隐私.最近,百度开始支持PC端HTTPS SSL加密搜索,现在可以启用 https://www.baidu.com 搜索.我很少 ...

  10. [转] Asp.net Report Viewer 简单实例

    原文链接:http://www.aspsnippets.com/Green/Articles/ASPNet-Report-Viewer-control-Tutorial-with-example.as ...