lz最近在慢慢看android开发
看完书上一个例子后就动手模仿了下...虽然书上和教学视频上说的很多了 但lz手拙做了好久效果如下(没有任何业务功能的...只是界面):
也就是一个最常见的菜单栏和一个弹出菜单(图片资源,教程等都是李兴华老师的android实战开发经典里的)
这里是lz的一些总结和思考(lz的一些思考过程 大家可以借鉴一下 虽然不是很好的思路的说 ):
思路啊~在做之前要想清楚 界面是怎样的首先要确定好布局之间的关系 主界面中: 最大的是一个RelativeLayout里面有一个显示的面板LinearLayout和一个菜单栏GridView
[mw_shl_code=xml,true]<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android rientation="vertical" >
</LinearLayout>
<GridView
android:id="@+id/grad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:fadingEdge="vertical"
android:fadingEdgeLength="5dp" />
</RelativeLayout>[/mw_shl_code]
弹出菜单中: 原本Android提供的PopupWindow不够吃的话自己继承一下咯(一定要先调用super(context)) 那些字的一行是一个GridView 图片也是一个GridView 那怎么把两个放在一起呢?
再加一个布局管理器吧
于是这两个GridView放在LinearLayout中 那么这个LinearLayout对象就是要显示的东西喽
就把LinearLayout作为显示内容的View(contentViw) 继承的PopupWindow的构造方法内的一些代码:
[mw_shl_code=java,true] layout=new LinearLayout(context);
layout.addView(title);
layout.addView(body);
layout.setOrientation(LinearLayout.VERTICAL);
this.setContentView(layout);
super.setBackgroundDrawable(new ColorDrawable(bg));
super.setWidth(LayoutParams.FILL_PARENT) ;
super.setHeight(LayoutParams.WRAP_CONTENT) ;
super.setFocusable(true);[/mw_shl_code]
既然用到了GridView 那么一定会要用Adapter的 两个是配套使用的 一个显示 一个提供显示的内容
但API提供的在实际情况中好像都不够吃的样子.... 为了让Adapter有更好的扩展性 可以自己继承一下BaseAdapter并覆写方法 思考一下Adapter需要完成的工作 如果点击一个图标 则该图标处于被选中的状态 图标的背景或者文字的颜色需要改变 这个功能是让包裹这个图标的GridView完成呢还是由图标所在的Adapter完成呢? 其实都可以不过在Adapter中完成更加方便(我的理解啦) 只要将Listenrer中得到的position传入Adapter的一个方法就可以了: [mw_shl_code=java,true]public void setFocus(int position){
for(int x=0;x<titles.length;x++){
if(x==position){
titles[x].setTextColor(fgColorSelect);
titles[x].setBackgroundColor(bgColorSelect);
}else{
titles[x].setTextColor(fgColor);
titles[x].setBackgroundColor(bgColor);
}
}[/mw_shl_code]
这样也知道在构造函数中需要传入的东西了:
context是一定要的,
一个表示资源ID的int数组,
默认的颜色,
被选中的颜色.(其他比如是文字的话文字大小之类的也要吧 想到就加啦~ ~~):
[mw_shl_code=java,true]private Context context=null;
private TextView[] titles=null; //title數組
private int bgColor=0; //背景顏色
private int bgColorSelect=0; //選中時的背景顏色
private int fgColor=0; //前景顏色
private int fgColorSelect=0; //選中時的前景顏色
public TitleGridAdapter(Context context, int[] titlesRes, int bgColor,int bgColorSelect, int fgColor, int fgColorSelect,int textSize) {
......[/mw_shl_code]
这是lz今天在做的东西..看完视频后 模仿一步一步来的.最后也差不多做好了 其实有时候代码不难 就是关系很难理清楚 不过做得多了也就好了啦 lz现在做着还不是很顺手 因为思路不够开阔的样子啊 .......
做美工的孩子们都是辛苦的孩子们...都是有创造力的孩子们 
|