自定义控件:抽屉SlidingDrawer——wrap_content非全屏

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非全屏的更多相关文章
- OSG 初始化为非全屏窗口
OSG默认的窗口时全屏的,调试的时候不方便. 在网上看到一段代码,可以非全屏显示 int _tmain(int argc, _TCHAR* argv[]){ osgViewer::Viewer vie ...
- 微信非全屏播放设置(仅Iphone)
由于微信X5内核强制视频全屏,用X5自带内核播放,一般内嵌视频打开播放就会被全屏. ihpone里面可以通过设置 x-webkit-airplay="true" webkit-pl ...
- IOS(苹果手机)使用video播放HLS流,实现在内部播放及全屏播放(即非全屏和全屏播放)。
需求: 实现PC及移动端播放HLS流,并且可以自动播放,在页面内部播放及全屏播放功能. 初步:PC及安卓机使用hls.js实现hls流自动播放及全屏非全屏播放 首先使用了hls.js插件,可以实现在P ...
- 为cocos2d-x实现安卓输入框。非全屏,无dialog,绑定到lua
cocos2d-x官方自带的输入框,简直惨不忍睹,在ios还好,在安卓简直了..用过的都知道... 所以为了用户体验,我们自己搞一个吧.输入框这种东西比较特殊,不像按钮.列表框之类的很容易实现,因为涉 ...
- 【Win 10应用开发】实现全屏播放的方法
有人会问,以前的MediaElement控件不是有现成的一排操作按钮吗?而且可以直接进入全屏播放.是的,我们知道,以往的Store App都是在全屏模式下运行的,只要MediaElement控件填满整 ...
- VirtualBox全屏切换
用VirtualBox的时候,如果设置为全屏,想再切换回来,没有什么菜单,只有通过键盘的快捷键来操作,才可以恢复. 我常常忘掉,所以老是得去找,以后需要记住这几个按键的快捷键. 1.全屏与非全屏切换: ...
- 如何制作一个完美的全屏视频H5
写在前面的话: 最近一波H5广告火爆整个互联网圈,身为圈内人,我们怎能 不! 知!道! :( 嘘!真不知道的也继续看下去,有收获 ↓ ) So,搞懂这个并不难. 这篇文章将带你从头到尾了解H5 ...
- JS 取消iOS播放自动全屏:
iOS下浏览器模式下h5播放器强制是全屏的,除非在app下才可以非全屏播放,需要两个配置: (1)播放器添加参数: playsinline:true(我使用的是阿里云的播放器,其他的需要自己找找是那个 ...
- C# WinForm 关于窗体最大化时的是否全屏效果与是否遮盖任务栏
0.新建窗体 及添加按钮 1. 执行如下按钮事件 private void btnFormMax_Click(object sender, EventArgs e) { if (this ...
随机推荐
- javascript分享到的源码
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- C# get set方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- hdu1021 Fibonacci Again
http://acm.hdu.edu.cn/showproblem.php?pid=1021 //找规律.. #include<iostream> #include<stdio.h& ...
- Android中XML格式数据的简单使用
源码: package com.wangzhu.demo; import java.io.IOException; import java.io.StringWriter; import javax. ...
- MSSQLServer基础07(事务,存储过程,分页的存储过程,触发器)
事务 事务:保证多个操作全部成功,否则全部失败,这处机制就是事务 思考:下了个订单,但是在保存详细信息时出错了,这样可以成功吗? 数据库中的事务:代码全都成功则提交,如果有某一条语句失败则回滚,整体失 ...
- C++:虚函数的引入
5.4虚函数5.4.1 虚函数的引入 //例5.19 虚函数的引例 #include<iostream> using namespace std; class MyBase{ //声明基类 ...
- makefile使用
linux make手册:http://www.gnu.org/software/make/manual/make.html 一篇文章: 假设我们有一个程序由5个文件组成,源代码如下:/*main.c ...
- Xmanager Enterprise Linking VM Redhat Linux AS4.7 X64–Server Configuration
[root@localhost ~]# vi /etc/inittab ## inittab This file describes how the INIT process shou ...
- 面试题_93_to_102_编程和代码相关的面试题
93)怎么检查一个字符串只包含数字?(解决方案) 94)Java 中如何利用泛型写一个 LRU 缓存?(答案<) 95)写一段 Java 程序将 byte 转换为 long?(答案) 95)在不 ...
- jenkins mac slave 设置
1.在jenkins上增加节点, 2,在mac系统中将ssh的服务打开在偏好设置- 互联网与无线 - 共享中 3,使用mac root用户修改sshd-config的鉴权方式 首先获取到root用户登 ...