2010-08-26 35 views
1

朋友的, 我有任務設置菜單水平滾動兩端的圖像顯示菜單的可用性。我通過使用圖庫視圖來完成,但是我需要在菜單之間放置一個分隔符(垂直線),我無法在畫廊之間獲得分隔符。 我怎樣才能得到它。如何設置水平滾動菜單欄

我需要以下

 ---------------------------------------- 
     < menu1  | menu2 | menu3 > 
     ----------------------------------------- 

的觀點只是指CBSNews應用如果u有。

在此先感謝。

回答

1

基本想法是包括分離到佈局爲畫廊的項目,如:

<View android:id="@+id/separator" android:background="#000" 
    android:layout_height="80dip" 
    android:layout_marginLeft="5sp" android:layout_marginRight="15sp" 
    android:layout_width="3sp" 
    android:layout_alignParentLeft="true"></View> 

<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="100dip" 
    android:layout_toRightOf="@id/separator" 
    android:layout_height="80dip" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <ImageView android:id="@+id/imageView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="centerInside"></ImageView> 
</RelativeLayout> 

然後,在你SimpleAdapter派生類,隱藏在分離器具有位置0的項目:

public View getView(int position, View convertView, ViewGroup parent) { 

     View view = super.getView(position, convertView, parent); 
     View separator = view.findViewById(R.id.separator); 
     if (separator != null) 
      separator.setVisibility(position == 0 ? View.GONE : View.VISIBLE); 
     return view; 
    } 

設置圖庫s以便與佈局中設置爲分隔符的邊距很好地對應。