UI篇--布局问题
1、android:layout_marginRight 不起作用解决方法
今天想在RelativeLayout的左右分别放上一个按钮,
左边按钮用marginLeft="10dp",空出了10dp的距离,没问题.
但是右边的按钮marginRight="10dp"就是过不去.
试了很久,最后在这个代码前加了一条android:layout_alignParentRight="true"
2、自定义控件增加滚动条,有的时候需要自己定义一些view,类似于listView,ScrollView。
自定义的view是没有滚动条的,
一种办法就是继承ScrollView,会自动带滚动条;
另一种需要自定义view,继承view或者frameLayout.
自己添加滚动条。
修改样式文件,添加需要的样式就可以了。
例如:自定义的viewgroup控件如何加滚动条呢,就是设置高度啦
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (!isNewCompose) { getScrollLayoutParams(); } //将高度设置的足够的长 setMeasuredDimension(mViewWidth, ((mRow + 1) * mChildHeight + VIEW_MARGIN * (mRow + 1) * 2)); }
3、gridview中无法响应ImageButton的click事件
gridview的每一个元素的布局如下:cell_book_item.xml
<RelativeLayout android...> <ImageButton android... /> <TextView android:id="@+id/bookname" .../> </RelativeLayout>
activity_bookshelf.xml
<RelativeLayout android...> <com.myViewGroup xmlns:android="http://..." /></RelativeLayout>
需要将ImageButton修改为ImageView,点击事件变成了gridview的OnItemClickListener事件了。
4、android gridview中会放button组件后,怎样加button的侦听事件
android gridview中能放button组件后,怎样加button的侦听事件我用SimpleAdapter在gridview里面加button组件,但是不知道该怎样给这些button添加侦听事件。。求教
------解决方案--------------------
button.setOnClickListener()
------解决方案--------------------
在 adapter 的getview 里面 获取buttton 然后 button.setonclicklistener
------解决方案--------------------
继承一个SimpleAdapter,通过getView里面可以获得position,然后将button.setId(position);
------解决方案--------------------
如果你的gridview只是button不需要丰富设计的话,可以这样
grid.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) { switch(position){//position是你选中的button的位置(第几个) case 0: .... } } });
5、gridview中ImageButton响应事件,该如何解决
gridview中ImageButton响应事件
我的gridview中有很多的图片按钮,可是无法响应onItemClick事件,我用了网上说的加个android:focusable="false";还是不行,我想做的是单击不同的图片按钮跳转到不同的页面,做了一天都没把这问题解决,急死了,请教了
方法1:
给ImageButton加上这个android:focusable="false"属性
给GridView的每一个item的布局文件中的最外层的layout加上这个属性android:descendantFocusability="blocksDescendants"
方法2:
android 中GridView 的Item中有一个ImageView 和一个ImageButton,可以实现点击ImageButton的监听器吗?
onItemClick中再写一个监听就行了
@Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
ImageView Left = (ImageView) v.findViewById(R.id.left); m_ClickNum =1; Left.setOnClickListener(new View.OnClickListener(){ public void onClick(View arg0) { m_ClickNum ++ ; } });
ImageView Right = (ImageView) v.findViewById(R.id.right); m_ClickNum =1; Right.setOnClickListener(new View.OnClickListener(){ public void onClick(View arg0) { m_ClickNum ++ ; } });}
测试了下,GridView的单元中如果还有ImageButton就不能监听了,使用ImageView是可以的。
更多相关文章
- Android(安卓)BLE蓝牙开发中读取数据时设置Notify的方法
- Android(安卓)广播事件机制
- android之listener
- Android防止过快点击造成多次事件
- Android(安卓)技术专题系列之二 -- telephony(转载)
- 对Menu Button 说再见
- 【Android游戏开发十五】关于Android(安卓)游戏开发中 OnTouchEv
- android EditText监听事件处理方法
- Android(安卓)按键事件响应