0

虽然这个问题听起来像是其他人的欺骗,但我试图在小部件中执行此操作的事实大大限制了我在其他地方使用建议的解决方案的能力。

总结:我想在列表中最顶部的项目上方和最底部的项目下方添加间距,以使它们远离标题栏和底部栏边缘。

本质上,我试图解决与在 Android 中的顶部 ListView 项目上方(以及最后一个下方)添加边距相同的问题,但是,我不能依赖对我的 ListView 对象的引用来设置标题()或类似的东西。

这真的不可能在 Android 小部件中做到吗?

4

3 回答 3

0

So ,here i have override function of adapter.From this function you can change or specify margin,height.Here you need to take object of Layout which you are using and from this you can change layout attributes.

 @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 ;

//HOPE IT HELP

于 2014-04-04T06:21:37.357 回答
0

我假设您正在为您的 ListView 使用适配器,因此您正在夸大额外的 listview 布局。在一个getView方法中,根据列表项位置(0 和最后一个),放置底部或顶部填充。

于 2012-09-14T06:10:48.933 回答
-1

在 getView() 期间在适配器中检查它是位置 0 还是 .getLength() 并在 convertView 上设置 LayoutParams

于 2012-09-14T18:43:13.730 回答