2013-11-27 32 views
0

我有一個圖片庫,和畫廊有一個默認選擇中心,看圖片如何左選擇器庫android?

gallery1

我不需要左側的空間,所以我需要一個左選擇,所看到的畫面:

gallery2

這是我的代碼

final Gallery galay = (Gallery)findViewById(R.id.gallerylay); 

galay.setAdapter(new layoutAdapter(this)); 
galay.setSpacing(50); 
    .................. 

public class layoutAdapter extends BaseAdapter { 

    private Context ctx; 


    public layoutAdapter(Context c) { 
     ctx = c; 
    } 

    @Override 
    public int getCount() { 

     return pics1.length; 
    } 

    @Override 
    public Object getItem(int arg0) { 

     return arg0; 
    } 

    @Override 
    public long getItemId(int arg0) { 

     return arg0; 
    } 

    @Override 

    public View getView(int arg0, View arg1, ViewGroup arg2) { 

     // Declare Variables 
     TextView txtrank; 
     TextView txtcountry; 
     TextView txtpopulation; 
     TextView imgflag; 
     View itemView = (arg1 == null) ? View.inflate(ctx, R.layout.slide, null) :arg1; 

     Gallery.LayoutParams innerLP = new Gallery.LayoutParams(250, 350); 

     itemView.setLayoutParams(innerLP); 
     itemView.setBackgroundResource(R.drawable.cadre1); 
     txtrank=(TextView) itemView.findViewById(R.id.textView1); 
     txtrank.setText(pics1[arg0]); 
     return itemView; 
    }} 

請問我該怎麼做?

+0

具有u使用XML來實現這一目標 –

回答

0

您是否在XMl中實施了圖庫視圖?如果是,那麼設置

android:verticalSpacing="5dp" 
android:horizontalSpacing="5dp" 
android:columnWidth="70dp" 
android:stretchMode="columnWidth" 
+0

非它是硬編碼 – slama007

+1

檢查此鏈接http://stackoverflow.com/questions/5404590/gallery-default-item-selected-is-in-中央 –