`
shuai1234
  • 浏览: 936641 次
  • 性别: Icon_minigender_1
  • 来自: 山西
社区版块
存档分类
最新评论

高仿iReader书架效果

 
阅读更多

 

 阅读过电子书的朋友相信对iReader都是比较熟悉的,iReader的书架做的非常漂亮,以前总以为是使用了2D画图做的呢,今天反编译了一下才明白原来是用图片拼接起来的,这样就OK了,今天我就带大家实现一个iReader书架。

         首先看一下layout下main.xml布局:

 

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <RelativeLayout  
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="@drawable/bookshelf_header_bg" >  
  11.   
  12.         <ImageView  
  13.             android:id="@+id/shelf_image_title"  
  14.             android:layout_width="wrap_content"  
  15.             android:layout_height="wrap_content"  
  16.             android:layout_centerInParent="true"  
  17.             android:background="@drawable/bookshelf_header_logo" />  
  18.   
  19.         <Button  
  20.             android:id="@+id/shelf_image_button"  
  21.             android:layout_width="wrap_content"  
  22.             android:layout_height="wrap_content"  
  23.             android:layout_alignParentRight="true"  
  24.             android:background="@drawable/bookshelf_goto_bookcity_f" />  
  25.     </RelativeLayout>  
  26.   
  27.     <ListView  
  28.         android:id="@+id/shelf_list"  
  29.         android:layout_width="fill_parent"  
  30.         android:layout_height="fill_parent"  
  31.         android:scrollbars="none"  
  32.         android:divider="#00000000"  
  33.         android:cacheColorHint="#00000000"/>  
  34.   
  35. </LinearLayout>  

      由于书架是用图片拼成的,所以每一个行的数据框都是一个listview ,  看一些listview对应的item布局:

 

 

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent" >  
  5.   
  6.     <ImageView  
  7.         android:id="@+id/shelf_image_left"  
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:layout_alignParentLeft="true"  
  11.         android:layout_centerVertical="true"  
  12.         android:background="@drawable/bookshelf_layer_left" />  
  13.   
  14.     <LinearLayout  
  15.         android:id="@+id/linearLayout1"  
  16.         android:layout_width="wrap_content"  
  17.         android:layout_height="wrap_content"  
  18.         android:layout_centerVertical="true"  
  19.         android:layout_toLeftOf="@+id/shelf_image_right"  
  20.         android:layout_toRightOf="@+id/shelf_image_left"  
  21.         android:background="@drawable/bookshelf_layer_center"  
  22.         android:orientation="horizontal" >  
  23.   
  24.         <LinearLayout  
  25.             android:layout_width="wrap_content"  
  26.             android:layout_height="wrap_content"  
  27.             android:layout_weight="1"  
  28.             android:gravity="center_horizontal" >  
  29.   
  30.             <Button  
  31.                 android:id="@+id/button_1"  
  32.                 android:layout_width="80dip"  
  33.                 android:layout_height="110dip"  
  34.                 android:layout_marginTop="15dip"  
  35.                 android:background="@drawable/default_cover" />  
  36.         </LinearLayout>  
  37.   
  38.         <LinearLayout  
  39.             android:layout_width="wrap_content"  
  40.             android:layout_height="wrap_content"  
  41.             android:layout_weight="1"  
  42.             android:gravity="center_horizontal" >  
  43.   
  44.             <Button  
  45.                 android:id="@+id/button_2"  
  46.                 android:layout_width="80dip"  
  47.                 android:layout_height="110dip"  
  48.                 android:layout_marginTop="15dip"  
  49.                 android:background="@drawable/default_cover" />  
  50.         </LinearLayout>  
  51.   
  52.         <LinearLayout  
  53.             android:layout_width="wrap_content"  
  54.             android:layout_height="wrap_content"  
  55.             android:layout_weight="1"  
  56.             android:gravity="center_horizontal" >  
  57.   
  58.             <Button  
  59.                 android:id="@+id/button_3"  
  60.                 android:layout_width="80dip"  
  61.                 android:layout_height="110dip"  
  62.                 android:layout_marginTop="15dip"  
  63.                 android:background="@drawable/default_cover" />  
  64.         </LinearLayout>  
  65.     </LinearLayout>  
  66.   
  67.     <ImageView  
  68.         android:id="@+id/shelf_image_right"  
  69.         android:layout_width="wrap_content"  
  70.         android:layout_height="wrap_content"  
  71.         android:layout_alignParentRight="true"  
  72.         android:layout_centerVertical="true"  
  73.         android:background="@drawable/bookshelf_layer_right" />  
  74.   
  75. </RelativeLayout>  

     最后是把item绑定到listview中:

 

 

[html] view plaincopy
  1. package cn.com.karl.reader;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.view.LayoutInflater;  
  6. import android.view.View;  
  7. import android.view.ViewGroup;  
  8. import android.view.Window;  
  9. import android.widget.BaseAdapter;  
  10. import android.widget.ListView;  
  11.   
  12. public class IReaderActivity extends Activity {  
  13.     /** Called when the activity is first created. */  
  14.     private ListView shelf_list;  
  15.     // 书架的列数  
  16.     int[] size = new int[5];  
  17.   
  18.     @Override  
  19.     public void onCreate(Bundle savedInstanceState) {  
  20.         super.onCreate(savedInstanceState);  
  21.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
  22.         setContentView(R.layout.main);  
  23.   
  24.         shelf_list = (ListView) findViewById(R.id.shelf_list);  
  25.           
  26.         ShelfAdapter adapter = new ShelfAdapter();  
  27.         shelf_list.setAdapter(adapter);  
  28.     }  
  29.   
  30.     public class ShelfAdapter extends BaseAdapter {  
  31.           
  32.   
  33.         @Override  
  34.         public int getCount() {  
  35.             // TODO Auto-generated method stub  
  36.             return size.length;  
  37.         }  
  38.   
  39.         @Override  
  40.         public Object getItem(int position) {  
  41.             // TODO Auto-generated method stub  
  42.             return size[position];  
  43.         }  
  44.   
  45.         @Override  
  46.         public long getItemId(int position) {  
  47.             // TODO Auto-generated method stub  
  48.             return position;  
  49.         }  
  50.   
  51.         @Override  
  52.         public View getView(int position, View convertView, ViewGroup parent) {  
  53.             // TODO Auto-generated method stub  
  54.             View layout = LayoutInflater.from(getApplicationContext()).inflate(  
  55.                        R.layout.list_item, null);  
  56.           
  57.             return layout;  
  58.         }  
  59.   
  60.     }  
  61.   
  62. }  
 

 

    每一本书对应的点击事件这里并没有做,相信大家可以实现,OK,下面看一下运行后效果:

 


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics