2012-09-14 54 views
0

儘管這個問題聽起來像是其他人的愚蠢行爲,但我試圖在小工具中這樣做的事實大大限制了我在別處使用所提議的解決方案的能力。Android小工具:在小工具中爲ListView添加頂部邊距

總結:我想在列表中最上面的項目上方和最下方的項目下方添加間距,以便將它們從標題欄和底部欄邊緣偏移。

本質上,我試圖解決與Add margin above top ListView item (and below last) in Android相同的問題,但是,我不能依靠對ListView對象的引用來setHeader()或類似的東西。

這是真的不可能在Android小部件中做?

回答

0

我假設你正在爲你的ListView使用一個適配器,所以你正在充氣其他的listview佈局。在getView方法中,根據列表項位置(0和last),放置底部或頂部填充。

在適配器
+0

我怎麼會去把使用RemoteViews是填充? – RealCasually

-1

getView()時檢查它是否是任何一個位置0或.getLength(),並在convertView設置的LayoutParams有

0

所以,在這裏我有adapter.From的覆蓋功能,此功能可以更改或指定邊距,height.Here你需要採取佈局,你正在使用的對象,並從中你可以改變佈局屬性。

@Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      if (convertView == null) { 
       LayoutInflater mInflater = (LayoutInflater) context 
         .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
       convertView = mInflater.inflate(R.layout.drawer_list_item, null); 
      } 
      if (position == 0) {//for first row 



       ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon); 
       TextView txtTitle = (TextView) convertView.findViewById(R.id.title); 

       RelativeLayout.LayoutParams relate = new RelativeLayout.LayoutParams(200, 200); 
       relate.setMargins(150, 0, 0, 0); 

       imgIcon.setLayoutParams(relate); 
       RelativeLayout.LayoutParams text = new RelativeLayout.LayoutParams(300, 100); 
       text.setMargins(150, 180, 0, 0); 


       } 
    return convertView ; 

//希望它HELP