我ListView里面使用了mListView.addHeaderView(rollView);方法添加了图片滑动的效果。请问这效果为什么啊?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我ListView里面使用了mListView.addHeaderView(rollView);方法添加了图片滑动的效果。请问这效果为什么啊?相关的知识,希望对你有一定的参考价值。
参考技术A 你可以在加个addHeaderView,里面用个viewpager,显示你的广告图片,还可以滑动哦答题不易,互相帮助,手机提问的朋友在客户端右上角评价点满意即可.
如认可我的回答,请点击采纳为满意回答按钮. 参考技术B 是问为什么不回去?你下拉刷新的问题吧追问
我下拉刷新的时候也在其他类的方法中使用了addHeaderView的方法,会不会是冲突啊?不能使用2个addHeaderView?
追答addHeaderView是一个对像的方法,只要确定是哪个对像在调用就不会冲突
本回答被提问者采纳ListView之在Activity里面重写item里面的事件
ListView是android里面用到很多的一个控件,这使用起来比较简单,又很实用。今天要讲的就是在Activity进而 重写Adapter的Button事件,废话不多说,就直接开始了 1、创建一个适配器FindAdapter.java public class FindAdapter extends CursorAdapter implements OnClickListener{ private Context context;//this context private OnItemFindClick onItemFindClick; public FindAdapter(Cursor cursor){ super( IM.im, cursor, FLAG_REGISTER_CONTENT_OBSERVER ); } public View getView(int pos, View convertView, ViewGroup parent) { return renderUser(pos,convertView,parent); } // 将分割线放在上面,利于判断 public View renderUser(int pos,View view,ViewGroup parent){ FindHolder findHolder = null; if(view == null){ view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.tt_item_find, parent,false); findHolder = new FindHolder(view); findHolder.btnRefuse.setOnClickListener(this); findHolder.btnRefuse.setTag(pos);//这里很容易忘记 findHolder.btnAccept.setOnClickListener(this); findHolder.btnAccept.setTag(pos); view.setTag(findHolder); }else{ //ant findHolder = (FindHolder)view.getTag(); } Cursor cursor = (Cursor)getItem(pos); String accountStr = cursor.getString(cursor.getColumnIndex(ContactProvider.ContactColumns.ACCOUNT)); String nameStr = cursor.getString(cursor.getColumnIndex(ContactProvider.ContactColumns.NAME)); findHolder.tvAccount.setText(accountStr+""); findHolder.tvName.setText(nameStr); findHolder.ivcAvatar.setImageDrawable(IM.getAvatar(accountStr)); return view; } public void setOnItemFindClick(OnItemFindClick onItemFindClick){ this.onItemFindClick = onItemFindClick; } class FindHolder{ TextView tvAccount; TextView tvName; ImageViewCircle ivcAvatar; Button btnRefuse; Button btnAccept; public FindHolder(View v){ tvAccount = (TextView)v.findViewById(R.id.tt_item_find_account); tvName = (TextView)v.findViewById(R.id.tt_item_find_name); ivcAvatar = (ImageViewCircle)v.findViewById(R.id.tt_item_find_icon); btnRefuse = (Button)v.findViewById(R.id.tt_item_find_refuse); btnAccept = (Button)v.findViewById(R.id.tt_item_find_accept); } } public interface OnItemFindClick{ public void onAcceptClick(View v); public void onRefuseClick(View v); } public void onClick(View v) { switch(v.getId()){ case R.id.tt_item_find_accept://答应请求 onItemFindClick.onAcceptClick(v); break; case R.id.tt_item_find_refuse://拒绝请求 onItemFindClick.onRefuseClick(v); break; } } public void bindView(View arg0, Context arg1, Cursor arg2) {} public View newView(Context arg0, Cursor arg1, ViewGroup arg2) { return null; } } 2.当然需要一个布局哦!这里是我的布局tt_item_find.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical" > <com.chat.ui.widget.ImageViewCircle android:id="@+id/tt_item_find_icon" android:layout_width="45dp" android:layout_height="45dp" android:layout_marginLeft="10dp" android:scaleType="centerCrop" android:src="@drawable/tt_login_logo" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginLeft="10dp" > <TextView android:id="@+id/tt_item_find_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/contact_realname_color" android:textSize="17sp" /> <TextView android:id="@+id/tt_item_find_account" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/contact_name_color" android:textSize="12sp" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right" android:orientation="horizontal" android:layout_marginRight="10dp"> <Button android:id="@+id/tt_item_find_accept" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:background="@drawable/tt_show_head_toast_bg" android:text="@string/tt_item_find_accept" android:textColor="@color/contact_realname_color" android:paddingLeft="5dp" android:paddingRight="5dp"/> <Button android:id="@+id/tt_item_find_refuse" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/tt_show_head_toast_bg" android:text="@string/tt_item_find_refuse" android:textColor="@color/contact_realname_color" android:paddingLeft="5dp" android:paddingRight="5dp"/> </LinearLayout> </LinearLayout> 3.现在item开始了,就开始写Activity了 public class FindActivity extends Activity implements OnItemFindClick{ private ListView list; private FindAdapter findAdapter; private OnItemFindClick onItemFindClick; private Cursor cursor; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initPatent(); init(); initData(); } //cursor的数据自己去加载吧 private void initData(){} private void init(){ context = this; list = (ListView)contentView.findViewById(R.id.tt_activity_find_list); onItemFindClick = this; findAdapter = new FindAdapter(cursor); findAdapter.setOnItemFindClick(onItemFindClick); list.setAdapter(findAdapter); } //接受好友请求 public void onAcceptClick(View v) { Log.e("findActivity-->","accept"); Log.e("find---》",""+ v.getTag()); final Cursor cursor = (Cursor)findAdapter.getItem((Integer) v.getTag()); } //拒绝好友请求 public void onRefuseClick(View v) { Log.e("findActivity-->","refuse"); } } 4.activitty的布局自己去写吧!好了就完事了。
以上是关于我ListView里面使用了mListView.addHeaderView(rollView);方法添加了图片滑动的效果。请问这效果为什么啊?的主要内容,如果未能解决你的问题,请参考以下文章
Flutter:ListView 里面的 ListView.builder
android listview 里面的item怎么让它居中?
ListView里面的ListView + control.Visibility