高仿QQ创建搜索框以及拼音检索好友

  • 以前用qq写日志能写出一万字的扯蛋文字,真要是写点什么有营养的东西就一脸的蒙逼,由于赶着项目每天过的云里雾里,总发现时间过的特别快,但是一天下来并没有觉得比昨天有多少进步,于是强迫自己试着写博客来记下自己的点点滴滴,就当算是一种成长吧。  废话不多说了,先简单介绍下项目,qq都用过吧,就是创建讨论组的那里有个输入框,当你点击item时,item对应的头像也会出现在输入框的左侧,下面的复选框也对应的勾上,当然还可以拼音搜索,像这种效果:
  • 高仿QQ创建搜索框以及拼音检索好友_第1张图片

  • 刚开始看到这种效果的时候觉得有点蒙逼,感觉是把头像直接嵌在edittext中,利用SpannableString字符长度来替换头像,代码量虽然不是很大,但是还是觉得比较麻烦,后来偶然看了一篇博客找到了点思路,经过两天的研究终于实现了这种效果。

  • 首先从布局分析:水平部分是一个横向滚动的HorizontalScrollView,右侧是一个edittext。
  • <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  •     android:layout_width="match_parent"
  •     android:layout_height="match_parent"
  •     android:background="@android:color/white"
  •     android:orientation="vertical" >

  •     <TextView
  •         android:id="@+id/text"
  •         android:layout_width="40dp"
  •         android:layout_height="20dp"
  •         android:layout_marginLeft="10dp"
  •         android:background="@android:color/holo_orange_light"
  •         android:gravity="center"
  •         android:text="0" />

  •     <RelativeLayout
  •         android:layout_width="match_parent"
  •         android:layout_height="60dp"
  •         android:background="@android:color/white"
  •         android:paddingLeft="10dp" >

  •         <HorizontalScrollView
  •             android:id="@+id/horizonMenu"
  •             android:layout_width="wrap_content"
  •             android:layout_height="match_parent"
  •             android:background="#ffffff"
  •             android:scrollbars="none" >

  •             <LinearLayout
  •                 android:id="@+id/llImg"
  •                 android:layout_width="wrap_content"
  •                 android:layout_height="match_parent"
  •                 android:background="@android:color/white"
  •                 android:gravity="center_vertical"
  •                 android:orientation="horizontal" >

  •                 <ImageView
  •                     android:id="@+id/imgEdiLeft"
  •                     android:layout_width="wrap_content"
  •                     android:layout_height="wrap_content"
  •                     android:background="@drawable/search"
  •                     android:scaleType="fitXY" />
  •             </LinearLayout>
  •         </HorizontalScrollView>

  •         <LinearLayout
  •             android:layout_width="match_parent"
  •             android:layout_height="match_parent"
  •             android:layout_marginLeft="10dp"
  •             android:layout_toRightOf="@+id/horizonMenu"
  •             android:background="@android:color/white"
  •             android:gravity="center_vertical"
  •             android:orientation="vertical"
  •             android:paddingRight="10dp" >

  •             <EditText
  •                 android:id="@+id/ediSeaarchGroup"
  •                 android:layout_width="match_parent"
  •                 android:layout_height="50dp"
  •                 android:background="@null"
  •                 android:drawablePadding="5dp"
  •                 android:gravity="center_vertical"
  •                 android:hint="搜索"
  •                 android:paddingRight="11dp"
  •                 android:singleLine="true"
  •                 android:textColor="@android:color/darker_gray"
  •                 android:textSize="14sp" />
  •         </LinearLayout>
  •     </RelativeLayout>

  •     <ListView
  •         android:id="@+id/lvGroup"
  •         android:layout_width="match_parent"
  •         android:layout_height="wrap_content"
  •         android:background="#00000000" >
  •     </ListView>

  • </LinearLayout>

  • 接下来


你可能感兴趣的:(高仿QQ创建搜索框以及拼音检索好友)