Android gallery里显示文字

来源:互联网 发布:辽宁省人工智能学会 编辑:程序博客网 时间:2024/05/22 01:56

有时候想 向左向右设置文字的变化 不妨试试gallery

Java代码  收藏代码
  1. "demo.xml"  
  2.   
  3. <?xml version="1.0" encoding="utf-8"?>  
  4. <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"  
  5. android:id="@+id/widget44"  
  6. android:layout_width="fill_parent"  
  7. android:layout_height="fill_parent"  
  8. android:orientation="vertical"  
  9. android:gravity="center_horizontal">  
  10.     <TextView  
  11.         android:id="@+id/txt1_gvi"  
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="wrap_content"  
  14.         android:textColor="#051b4d"  
  15.         android:gravity="center_horizontal"  
  16.         android:textColorHighlight="#656565"  
  17.         android:textSize="10sp">  
  18.     </TextView>  
  19. </LinearLayout>  

 

Java代码  收藏代码
  1. public Activity activity;  
  2.     private static LayoutInflater inflater=null;  
  3.     private String [] stringid=new String[]{"Index-Nifty","Positional calls","Intraday calls","InvestmentIdea","Optional calls","BTST-STBT calls"};       
  4.   
  5.     public TabGallary(Activity a) {       
  6.         activity = a;  
  7.         inflater =  (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
  8.     }  
  9.   
  10.     public int getCount(){  
  11.         return stringid.length;  
  12.     }     
  13.   
  14.     public Object getItem(int position) {  
  15.         return position;  
  16.     }  
  17.   
  18.     public long getItemId(int position) {  
  19.         return position;  
  20.     }  
  21.   
  22.     public View getView(int position, View convertView, ViewGroup parent)     
  23.     {             
  24.       View v;                       
  25.       if (convertView == null)   
  26.       {    
  27.            LayoutInflater li = getLayoutInflater();  
  28.            v = li.inflate(R.layout.demo, null);  
  29.            TextView tv1 = (TextView)v.findViewById(R.id.txt1_gvi);   
  30.            tv1.setText(stringid[position]);  
  31.            v.setOnClickListener(new OnClickListener()   
  32.            {                      
  33.                     @Override  
  34.                     public void onClick(View v)   
  35.                     {  
  36.                   // Call intent or perform ur activity;                  
  37.                     }  
  38.            });        
  39.       }  
  40.       else   
  41.       {  
  42.        v= convertView;  
  43.       }       
  44.   
  45.       return v;  
  46.    }  
原创粉丝点击