viewdragerhelper 里可以用listview吗
推出了ViewDragHelper这个类。
可以极大方便我们自定义viewgroup.
先看一个简单效果 一个layout里有2个图片 其中有一个可以滑动 一个不能滑
这个效果其实还蛮简单的(原谅我让臭脚不能动 让BABY动)
布局文件:
1
2
6
7 .example.administrator.viewdragertestapp.DragLayout
8 android:layout_width="match_parent"
9 android:layout_height="match_parent"
10 android:orientation="vertical">
11
12
18
19
25
26
27 <.example.administrator.viewdragertestapp.DragLayout>
28
29
然后我们看一下自定义的layout 如何实现2个子view 一个可以滑动 一个不能滑动的
1 .example.administrator.viewdragertestapp;
2
3 import android.content.Context;
4 import android.support.v4.widget.ViewDragHelper;
5 import android.util.AttributeSet;
6 import android.view.MotionEvent;
7 import android.view.View;
8 import android.widget.ImageView;
9 import android.widget.LinearLayout;
10 import android.widget.TextView;
11
12 /**
13 * Created by Administrator on 2015/8/12.
14 */
15 public class DragLayout extends LinearLayout {
16
17 private ViewDragHelper mDragger;
18
19 private ViewDragHelper.Callback callback;
20
21 private ImageView iv1;
22 private ImageView iv2;
23
24 @Override
25 protected void onFinishInflate() {
26 iv1 = (ImageView) this.findViewById(R.id.iv1);
27 iv2 = (ImageView) this.findViewById(R.id.iv2);
28 super.onFinishInflate();
29
30 }
31
32 public DragLayout(Context context) {
33 super(context);
34
35 }
36
37 public DragLayout(Context context, AttributeSet attrs) {
38 super(context, attrs);
39 callback = new DraggerCallBack();
40 //第二个参数就是滑动灵敏度的意思 可以随意设置
41 mDragger = ViewDragHelper.create(this, 1.0f, callback);
42 }
43
44 class DraggerCallBack extends ViewDragHelper.Callback {
45
46 //这个地方实际上函数返回值为true就代表可以滑动 为false 则不能滑动
47 @Override
48 public boolean tryCaptureView(View child, int pointerId) {
49 if (child == iv2) {
50 return false;
51 }
52 return true;
53 }
54
55 @Override
56 public int clampViewPositionHorizontal(View child, int left, int dx) {
57 return left;
58 }
59
60 @Override
61 public int clampViewPositionVertical(View child, , int dy) {
62 ;
63 }
64 }
65
66
67 @Override
68 public boolean onInterceptTouchEvent(MotionEvent ev) {
69 //决定是否拦截当前事件
70 return mDragger.shouldInterceptTouchEvent(ev);
71 }
72
73 @Override
74 public boolean onTouchEvent(MotionEvent event) {
75 //处理事件
76 mDragger.processTouchEvent(event);
77 return true;
78 }
79
80
81 }如何给gridview的注脚添加onclick事件
如何给gridview的注脚添加onclick事件
public class SinglePaneContainer extends FrameLayout implements Container { private ItemListView listView; public SinglePaneContainer(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onFinishInflate() { super.onFinishInflate(); listView = (ItemListView) getChildAt(0); } public boolean onBackPressed() { if (!listViewAttached()) { removeViewAt(0); addView(listView); return true; } return false; } @Override public void showItem(String item) { if (listViewAttached()) { removeViewAt(0); View.inflate(getContext(), R.layout.detail, this); } MyDetailView detailView = (MyDetailView) getChildAt(0); detailView.setItem(item); } private boolean listViewAttached() { return listView.getParent() != null; } }Android 如何判断一个View重绘或加载完成?
可以设置这个回调函数
//view重绘时回调
view.getViewTreeObserver().addOnDrawListener(new?OnDrawListener()?{
@Override
public?void?onDraw()?{
//?TODO?Auto-generated?method?stub
}
});//view加载完成时回调
view.getViewTreeObserver().addOnGlobalLayoutListener(new?OnGlobalLayoutListener()?{
@Override
public?void?onGlobalLayout()?{
//?TODO?Auto-generated?method?stub
}
});getMenuInflater().inflate(R.menu... menu字变红,什么问题?
在activity类中有一个getmenuinflater()的函数用来返回这个activity的menuinflater,并通过menuinflater对象来设置menu xml里的menu作为该activity的菜单。
setContentView,findViewById 和 inflate 的区别
通俗的说,inflate就相当于将一个xml中定义的布局找出来.
因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组件.
因此如果你的
Activity里如果用到别的layout,比如对话框上的layout,你还要设置对话框上的layout里的组件(像图片
ImageView,文字TextView)上的内容,你就必须用inflate()先将对话框上的layout找出来,然后再用这个layout对象去
找到它上面的组件,如:
View view = View.inflate(this, R.layout.dialog_layout, null);
TextView dialogTV = (TextView) view.findViewById();
dialogTV.setText("abcd");
如果组件是对话框上的组件,而你直接用this.findViewById(),那么返回值将是null
三种方式可以生成LayoutInflater :
LayoutInflater inflater = LayoutInflater.from(this);
LayoutInflater inflater = getLayoutInflater();
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
然后调用inflate方法将xml布局文件转成View
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
在View类中,也有inflate方法
public static View inflate (Context context, int resource, ViewGroup root)
findViewById有两种形式
R.layout.xx是引用res/layout/xx.xml的布局文件(inflate 方法),R.id.xx是引用布局文件里面的组件,组件的id是xx(findViewById方法)。
所有的组件id都能用R.id.xx来查看,但是组件不在setContentView()里面的layout中就无法使用,Activity.findViewById()会出现空指针异常
a. activity中的findViewById(int id)
b. View 中的findViewById(int id)
不同点是LayoutInflater是用来找layout下xml布局文件,并且实例化!而findViewById()是找具体xml下的具体
widget控件(如:Button,TextView等)。
Android View类中的生命周期是怎样的
android view有以下14个周期:
1、onFinishInflate() 当View中所有的子控件均被映射成xml后触发 。
2、onMeasure( int , int ) 确定所有子元素的大小 。
3、onLayout( boolean , int , int , int , int ) 当View分配所有的子元素的大小和位置时触发 。
4、onSizeChanged( int , int , int , int ) 当view的大小发生变化时触发 。
5、onDraw(Canvas) view渲染内容的细节。
6、onKeyDown( int , KeyEvent) 有按键按下后触发 。
7、onKeyUp( int , KeyEvent) 有按键按下后弹起时触发 。
8、onTrackballEvent(MotionEvent) 轨迹球事件 。
9、onTouchEvent(MotionEvent) 触屏事件 。
10、onFocusChanged( boolean , int , Rect) 当View获取或失去焦点时触发 。
11、onWindowFocusChanged( boolean ) 当窗口包含的view获取或失去焦点时触发 。
12、onAttachedToWindow() 当view被附着到一个窗口时触发 。
13、onDetachedFromWindow() 当view离开附着的窗口时触发,Android123提示该方法和 onAttachedToWindow() 是相反的。
14、onWindowVisibilityChanged( int ) 当窗口中包含的可见的view发生变化时触发。
今天有网友提到自己在Linux服务器中安装VNC桌面的时候安装都没有问题,但是在登录远程的时候居然有出现灰色界面,有三行代码提示"Accept clipboard from viewers,Send clipboard to viewers,Send primary selection to viewers"。即便我们重新登录也不行,这个到底如何解决呢?这里找几个可以解决的可能办法,我们多多尝试。...
公司成立于2021年,专注为用户提供低价高性能云计算产品,致力于云计算应用的易用性开发,面向全球客户提供基于云计算的IT解决方案与客户服务,拥有丰富的国内BGP、三线高防、香港等优质的IDC资源。公司一直秉承”以人为本、客户为尊、永续创新”的价值观,坚持”以微笑收获友善, 以尊重收获理解,以责任收获支持,以谦卑收获成长”的行为观向客户提供全面优质的互...
wordpress公司网站模板,wordpresss简洁风格的高级通用自适应网站效果,完美自适应支持多终端移动屏幕设备功能,高级可视化后台自定义管理模块+规范高效的搜索优化。wordpress公司网站模板采用标准的HTML5+CSS3语言开发,兼容当下的各种主流浏览器: IE 6+(以及类似360、遨游等基于IE内核的)、Firefox、Google Chrome、Safari、Opera等;同时...
onfinishinflate为你推荐
动态图片格式常见的动态图像文件格式有哪些?国家法规数据库哪个常用的法律APP比较好用?防火墙技术应用防火墙的应用与研究论文爱码验证码平台接码验证码接收平台如何使用?短信套餐移动有什么短信包月套餐,怎么开通?网页背景音乐代码有没有网页背景音乐播放器代码??飞信发信息要钱吗在飞信中发消息和发飞信短信有什么不同?要收费吗?camel是什么意思cantorp与骆驼是什么关系,想买一双骆驼鞋,分不清cantorp和camel骆驼是什么关系linux启动盘制作工具如何使用ultraiso制作LinuxU盘启动盘98系统98的系统怎么安?
重庆域名注册 域名备案网站 n点虚拟主机管理系统 3322动态域名 新加坡主机 Vultr 香港托管 抢票工具 ixwebhosting http500内部服务器错误 cdn联盟 hostloc 共享主机 中国网通测速 卡巴斯基免费试用版 优酷黄金会员账号共享 数据库空间 apnic 睿云 中国电信宽带测速 更多