2013-02-28 26 views
2

我想問一下關於Gmail應用程序中的操作欄。android:圖標和微調之間的差距

在主要活動中,操作欄(收件箱,發件等)中有一個微調框,並且沒有標題。

我在我的應用程序中嘗試過,但應用程序圖標和微調器之間存在比在Gmail應用程序中更大的差距。

我讓標題看起來既不可見又空白,但差距還是有點大。

我必須爲操作欄創建自己的視圖定義才能達到相同的效果嗎?

非常感謝, 馬丁

回答

2

謝謝大家的回答。的馬蒂亞斯答案領我到下面的解決方案,工作就像一個魅力:

public class ZeroPaddingArrayAdapter<T> extends ArrayAdapter<T> { 

    public InboxTypeAdapter(Context context, int textViewResourceId, T[] objects) { 
     super(context, textViewResourceId, objects); 
    } 

    public static ArrayAdapter<CharSequence> createFromResource(Context context, 
                   int textArrayResId, int textViewResId) { 
     CharSequence[] strings = context.getResources().getTextArray(textArrayResId); 
     return new ZeroPaddingArrayAdapter<CharSequence>(context, textViewResId, strings); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View view = super.getView(position, convertView, parent); 
     view.setPadding(
       0, 
        view.getPaddingTop(), 
       0, 
       view.getPaddingBottom() 
     ); 
     return view; 
    } 

} 

對於紡紗廠:

getView() - 獲取當前所選項目的視圖。 getDropDownView() - 獲取微調控制器打開時顯示的視圖。

我們只需要減少getView()中的填充。

只需使用此適配器而不是簡單的ArrayAdapter

+0

好東西,你在這裏發佈你的解決方案。但記得upvoting幫助你的答案;) – 2013-03-03 14:38:07

+0

嗨,Matthis。我很樂意,但是我需要15個聲望點才能做到這一點,我還沒有:-) – MartinCz 2013-03-04 11:48:49

+0

哈哈,完全忘了這一點。幹得好 ;) – 2013-03-04 13:31:56

1

創建具有正確填充爲你的動作條圖標繪製。

<?xml version="1.0" encoding="utf-8"?> 
<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item android:drawable="@drawable/logo" 
      android:right="10dp"/> 

</layer-list> 

然後只是設置爲清單中的圖標。你應該可以通過這種方式調整填充。

+0

嗨,聽起來很合理,但這並沒有給我帶來預期的結果:) – MartinCz 2013-03-03 07:56:17

1

降低Spinner的填充,在佈局中View即得到在AdaptergetView()方法充氣的更精確的填充。我只是在一個樣本項目中嘗試過,它顯着縮小了差距。

0

添加此行spinner.setPadding(0,0,0,0);在打開下拉菜單時隱藏向下箭頭圖像。