首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android仿照飘信例子

2012-07-04 
android模仿飘信例子?现在这是界面布局,,,没有实现功能,,,?首页的布局主要是GridView布局,再调用setAdapte

android模仿飘信例子

?现在这是界面布局,,,没有实现功能,,,

?

首页的布局主要是GridView布局,再调用setAdapter(adapter)传入 ,左右两边的小按钮,是用ImageButton 来做的图片的 切换,顶上中间的交友字样是TextView

?

GridView的实现简说

本程序用的是xml? 布局

?

xml代码

?

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
??? android:id="@+id/gridview"
??? android:layout_width="fill_parent"
??? android:layout_height="fill_parent"
??? android:numColumns="3"?
??? android:verticalSpacing="10dp"
??? android:horizontalSpacing="10dp"
??? android:columnWidth="70dp"?
??? android:stretchMode="columnWidth"??
??? android:gravity="center"
??? android:layout_marginTop="15dp"
?
/>

具体的元素说明可以在这个官方文档的这个文件找到? “R.attr.html”

?

构造adapter?

?


public class FriendImageAdapter extends BaseAdapter
{
??? // 定义Context
??? private? Context??? ??? mContext=null;
??? private final LayoutInflater layout;
??? private FriendActivity friendActivity=null;
??? // 定义整型数组 即图片源
???
??? private final Integer[]??? mImageIds??? =
??? {
??? ??? ??? R.drawable.mytpmobhome,
??? ??? ??? R.drawable.mylocationtpmob,
??? ??? ??? R.drawable.mytpmobfriend,
??? ??? ??? R.drawable.mynewtpmob,
??? ??? ??? R.drawable.mytpmobletter,
??? ??? ??? R.drawable.mysystemletter,
??? ???
??? };
???
???
??? private final Integer[]??? mStringId??? =
??? {???
??? ??? R.string.mytpmobhome,
??? ??? R.string.mylocationtpmob,
??? ??? R.string.mytpmobfriend,???
??? ??? R.string.mynewtpmob,
??? ??? R.string.mytpmobletter,
??? ??? R.string.mysystemletter,
??? ???
??? ???
??? };
?
??? public FriendImageAdapter(Context c)
??? {
??? ??? //得到activity对象
??? ??? mContext = c;
??? ??? friendActivity=(FriendActivity) c;
??? ??? //设置布局方式
??? ??? layout=(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
???
??? ???
??? ???
???
??? }
??? public void iniString(Context context){
??? ???
??? }

??? // 获取图片的个数
??? public int getCount()
??? {
??? ??? return mImageIds.length;
??? }

??? // 获取图片在库中的位置
??? public Object getItem(int position)
??? {
??? ??? return position;
??? }


??? // 获取图片ID
??? public long getItemId(int position)
??? {
??? ??? return position;
??? }
??? class Holer{
??? ??? ImageView imageView;
??? ??? TextView textView;
??? }
??? //构造视图View
??? Holer holer;
??? public View getView(int position, View convertView, ViewGroup parent)
??? {
??? ???
??? ??? if (convertView == null)
??? ??? {
??? ??? ???
??? ??? ??? holer=new Holer();
??? ??? ??? //构造图片上面和文字说明在下的布局
??? ??? ??? convertView=layout.inflate(R.layout.friendgrid_item, null);
??? ??? ??? holer.imageView=(ImageView) convertView.findViewById(R.id.frienditemImage);
??? ??? ??? holer.textView=(TextView)convertView.findViewById(R.id.frienditemText);
??? ??? ??? convertView.setTag(holer);
??? ??? ???
??? ??? }
??? ??? else
??? ??? {
??? ??? ??? ?holer = (Holer) convertView.getTag();
??? ??? }
??????? //传入位置
??? ??? holer.imageView.setImageResource(mImageIds[position]);
??? ??? holer.textView.setText(mStringId[position]);
??? ??? return convertView;
??? }

}

?

?

?

把adapter 存入Gridview?

?

??? public void iniGridView(){
??? ??? GridView gridview = (GridView) findViewById(R.id.myhomeview);???
??? ??? gridview.setAdapter(new FriendImageAdapter(this));??? ?????? ???
??? ??? gridview.setOnItemClickListener(new OnItemClickListener() {
??? ??? ??? public void onItemClick(AdapterView<?> parent, View v, int position, long id)
??? ??? ??? {
??? ??? ???
??? ??? ??? ??? funView(position);
??? ??? ??? }
??? ??? });
??? }

?

R.layout.friendgrid_item.xml的布局代码

?

?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
??? android:layout_height="wrap_content"
??? android:paddingBottom="4dip"
??? android:layout_width="wrap_content"
???
??? >
??? <ImageView android:layout_height="40px"
??? ??? android:id="@+id/frienditemImage"
??? ??? android:layout_width="40px"
??? ??? android:layout_centerHorizontal="true" >
??? </ImageView>
??? <TextView android:layout_width="wrap_content"
??? ??? android:layout_below="@+id/frienditemImage"
??? ??? android:layout_height="40px"??? ???
??? ??? android:layout_centerHorizontal="true"
??? ??? android:id="@+id/frienditemText">
??? </TextView>
???
</RelativeLayout>

?

?

?

ImageButton 图片转换的实现,主要是思想是用两个Item 放入两张图片,当做drawable资源,进行图片切换

?

ImageButton 在main.xml的布局代码

?

<ImageButton
?? android:id="@+id/logins"
?? android:layout_width="45dp"
?? android:layout_height="45dp"??
?? android:background="@drawable/button_login"
?? android:layout_gravity="right"
?? android:layout_marginRight="10dp"
?? android:layout_marginTop="4dp"?
?/>

?

?

ImageButton 里的backround 的button_login? 的xml代码布局

?

<selector xmlns:android="http://schemas.android.com/apk/res/android"??
??? android:layout_width="fill_parent"
??? android:layout_height="fill_parent"
??? >
? <item
?? android:state_pressed="false"
?? android:drawable="@drawable/buttonlogin01"
??
?? >
??
?? </item>
?? <item
?? android:state_pressed="true"
?? android:drawable="@drawable/buttonlogin02"
?? >
??
?? </item>

</selector>

?

这样主页基本就做好了,,,,,,,,,,,,,,,,,,,,,

?

地图页面的实现? ,点击主页的手机逛街就可以进入此页面

?

?

?

?

要使用android? map 必须要用 google apis 本程序用的是1.6版本? ,要看到效果还要生成一个Key

?

生成Key方法网上都可以找到,

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

1 楼 sunlips 2011-08-16   也不知道把这个没用的东西放上来干嘛,最基本的聊天都不能 2 楼 haitian235 2011-08-17   哈哈,,,,没有写完吗????只是布局而已。。。有空的时候再把这东西完善了,,,,忘多多包涵了。,,。。。

热点排行