仿爱奇艺界面(四)
搜索Activity的java内容虽然不多,只是找到两个gridView然后分别给他们设置适配器,但是布局文件里面包含的信息还是很丰富的。
SearchActivity:
?
public class SearchActivity extends Activity {GridView mHotGridView, mHistoryGridView;//热门搜索和搜索历史@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.search_activity);prepareView();}private void prepareView() {mHotGridView = (GridView) findViewById(R.id.hot_search_grid);mHotGridView.setAdapter(new GridAdapter(this));mHistoryGridView = (GridView) findViewById(R.id.history_search_grid);mHistoryGridView.setAdapter(new GridAdapter(this));}}
?接下来是适配器GridAdapter的代码,学习了gridView的话应该是轻车熟路了,把test1里面的倒霉熊什么的都写上去:
public class GridAdapter extends BaseAdapter {Context mContext;String[] test1 = new String[] { "开心魔法", "奋斗", "导火索", "碟中谍4", "碟中碟3","美人心计", "倒霉熊", "火影忍者", "喜洋洋", "北京爱情故事" };public GridAdapter(Context cnt) {this.mContext = cnt;}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn test1.length;}@Overridepublic Object getItem(int arg0) {// TODO Auto-generated method stubreturn null;}@Overridepublic long getItemId(int arg0) {// TODO Auto-generated method stubreturn 0;}@Overridepublic View getView(int arg0, View arg1, ViewGroup arg2) {// TODO Auto-generated method stubif (arg1 == null) {arg1 = LayoutInflater.from(mContext).inflate(R.layout.search_grid_item, null);}TextView tv = (TextView) arg1.findViewById(R.id.title);tv.setText(test1[arg0]);return arg1;}}
?布局文件里面用到的东西很多了,我把重点的讲下transparent这是图片重叠透明穿透,就是两张png的图片合在一块,不是覆盖。这里的效果就是摁下字,背景变了。
search_activity.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/phonetitlebar_bg" android:gravity="center" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/edittext_search" android:drawableLeft="@drawable/edittext_search_image" android:hint="@string/search_hit" android:paddingLeft="15dip" android:textSize="14dip" > </EditText> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_search_background" android:text="@string/search_text" /> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/search_main_tree_bg" android:gravity="center_vertical" android:paddingLeft="15dip" android:text="@string/hot_search" android:textColor="#000000" android:textSize="18dip" /> <GridView android:id="@+id/hot_search_grid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dip" android:layout_marginRight="30dip" android:layout_marginTop="15dip" android:layout_weight="1" android:horizontalSpacing="50dip" android:numColumns="2" android:listSelector="@drawable/list_seletor_transparent" android:scrollbars="none"> </GridView> <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/search_main_tree_bg" android:gravity="center_vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:paddingLeft="15dip" android:text="@string/search_history" android:textColor="#000000" android:textSize="18dip" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dip" android:background="@drawable/clear_but_background" android:text="@string/clear_search_history" android:textColor="#ffffff" /> </LinearLayout> <GridView android:id="@+id/history_search_grid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dip" android:layout_marginRight="30dip" android:layout_marginTop="15dip" android:layout_weight="1" android:horizontalSpacing="50dip" android:numColumns="2" android:listSelector="@drawable/list_seletor_transparent" android:scrollbars="none"> </GridView></LinearLayout>
?
search_grid_item.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/hot_search_background" android:paddingLeft="3dip" android:paddingBottom="3dip" android:paddingTop="3dip"> <TextView android:id="@+id/title" android:layout_width="80dip" android:layout_height="wrap_content" android:singleLine="true"/></LinearLayout>
?
PS:上面有些东西就没全部贴出来了,待会把整个源码贴上去,自己找了。