- 浏览: 253845 次
- 性别:
- 来自: 武汉
文章分类
- 全部博客 (195)
- android开发 (29)
- JAVA (3)
- android—Task (1)
- android—Folders (1)
- android—gallery (1)
- android—ListView (15)
- android—GridView (4)
- android—Notification (3)
- android—File (5)
- android—tabhost (3)
- android—uri (4)
- android—Shortcut (1)
- android—Imei (1)
- android—Vibrator (3)
- android—Voice (1)
- android 小案例练习 (2)
- android—Wifi (1)
- android—login (1)
- android—onKeyDown (1)
- android—Activity (12)
- android—onTouchEvent (2)
- android—thread (2)
- android—app (3)
- android—webview (2)
- android—Activity自动跳转 (2)
- android_sensor (1)
- android_URL (2)
- android—Googlemap (1)
- android TextView小练习 (1)
- android-apk (1)
- android -sqlite (2)
- Java -xml (1)
- rest (1)
- android-phone (2)
- android—image (7)
- android_intent (3)
- android——broadcastReceiver (2)
- Map (1)
- lock (0)
- android-background (2)
- android-cache (2)
- android-expandtab (2)
- android_UI控件实现 (0)
- android_viewfinderview (1)
- android-Popup (1)
- Android—TextView (0)
- Android-network (1)
- android_share (1)
- Android_pulldownview (0)
- android-Switch (1)
- android_actionbar (1)
- Android_scrollview (1)
- android_util (9)
- android-sparseArray (1)
- android_Adapter (1)
- Android—DatePicker (2)
- kjframeforandroid (1)
- DragSortListView (1)
- Afinal (1)
- Android-StaggeredGrid (1)
- SmoothProgressBar (1)
- ExplosionField (1)
- android-async-http (1)
- Android—circleindicator (1)
- android—stepsview (1)
- android—spanny (1)
- Android-ViewPager (2)
- android—pull layout (1)
- Android—time (1)
- PullToDismissPager (1)
- android—chart (1)
- android—pullzoomview (1)
- listviewfilter (1)
- andrAndroid-GIF (1)
- android—ListView,StickyScrollView (1)
- gradle (1)
- android—fragment (1)
- Android--Glide (2)
- Android - SharedPreferences (1)
- Android_imageview (2)
- dialog弹出框 (2)
- android-recyclerview (2)
- Android-Badger (1)
- android_dialog (2)
- android—RecyclerView (4)
- android TextView (1)
- android—topbar (1)
- android—轮播图效果 (1)
- Android—imageView (2)
- androidAndroid—button (1)
- 视频教程 (1)
- kotlin学习 (1)
- Android—tag (1)
- android—view (1)
- TabLayout (1)
- android-webView (1)
- rich-text (1)
- swiper标点样式 (1)
- image (1)
- ExpandableTextView (1)
- viewPager (0)
最新评论
-
龙哥IT:
把这些东西,放在一起,自己用的时候方便而已,不用到处找了
Android权限Uri.parse的几种用法 -
YURANUS_:
干货 哈哈哈
Android权限Uri.parse的几种用法 -
narutolzj:
楼主,AppUtils类是自定义的吗,找不到~~
获取安装的应用 -
black_smart:
...
Android权限Uri.parse的几种用法 -
liu_zheng:
博主 我想把文字换成图片 要怎么修改呢??
用linearLayout代替ListView
因为一个界面上面的内容太多,下面ListView查看不到,想在外面
加上scrollView,可是还是不行,结果没办法,用linearlayout代替
。对于具体要求,自己慢慢完善,这个相当于一个框架形式:
自己修改的地方:
public class AdapterForLinearLayout extends BaseAdapter { private LayoutInflater mInflater; private List<Map<String, Object>> data; public int count; private Context context; public AdapterForLinearLayout(Context context) { super(); this.context = context; this.mInflater = (LayoutInflater) context .getSystemService("layout_inflater"); this.data = new ArrayList<Map<String, Object>>(); count = data.size(); } public final class ListItemView {// 自定义控件集合 public TextView thread_number; public TextView thread_author; public TextView thread_time; public TextView thread_text; } public int getCount() { return data.size(); } public Object getItem(int position) { return data.get(position); } public long getItemId(int position) { return position; } public void addList(List<Map<String, Object>> mList) { data.addAll(mList); } public void remove(List<Map<String, Object>> mList) { data.remove(mList); } public View getView(int position, View convertView, ViewGroup arg2) { ListItemView listItemView = null; if (convertView == null) { listItemView = new ListItemView(); convertView = LayoutInflater.from(context).inflate( R.layout.forum_threaddetails_item, null); listItemView.thread_number = (TextView) convertView .findViewById(R.id.thread_number); listItemView.thread_author = (TextView) convertView .findViewById(R.id.thread_author); listItemView.thread_time = (TextView) convertView .findViewById(R.id.thread_time); listItemView.thread_text = (TextView) convertView .findViewById(R.id.thread_text); convertView.setTag(listItemView); } else { listItemView = (ListItemView) convertView.getTag(); } listItemView.thread_number.setText((String) data.get(position).get( "thread_number")); listItemView.thread_author.setText((String) data.get(position).get( "thread_author")); listItemView.thread_time.setText((String) data.get(position).get( "thread_time")); listItemView.thread_text.setText((String) data.get(position).get( "thread_text")); return convertView; } /** * 绑定视图 * * @param view * @param item * @param from */ private void bindView(View view, Map<String, Object> item, String from) { Object data = item.get(from); if (view instanceof TextView) { ((TextView) view).setText(data == null ? "" : data.toString()); } } }
/** * 绑定布局 */ public void bindLinearLayout() { int count = adapter.getCount(); for (int i = 0; i < count; i++) { View v = adapter.getView(i, null, null); v.setOnClickListener(this.onClickListener); if (i == count - 1) { LinearLayout ly = (LinearLayout) v; ly.removeViewAt(2); } addView(v, common.mNUM); common.mNUM++; } }
private ArrayList<Map<String, Object>> initValues() { list_buffer = CommonUtil.parseXml2(buffer, "r"); adapter = new AdapterForLinearLayout(this); ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); int total = common.CURRENTPAGE * common.PAGESIZE; if (list_buffer.size() <= 0) { // return; Toast.makeText(ThreadDetailsActivity.this, "没有回复内容", Toast.LENGTH_SHORT).show(); } else { if (total < list_buffer.size()) { addPageMore(); } for (int i = (common.CURRENTPAGE - 1) * common.PAGESIZE; i < total; i++) { if (total >= list_buffer.size()) { total = list_buffer.size(); } String mContent = (String) list_buffer.elementAt(i); detailAuthor = CommonUtil.parseXml(mContent, "a"); Content = CommonUtil.parseXml(mContent, "c"); floor = CommonUtil.parseXml(mContent, "l"); Time = CommonUtil.parseXml(mContent, "rt"); Map<String, Object> win = new HashMap<String, Object>(); win.put("thread_number", floor + "楼"); win.put("thread_author", detailAuthor); win.put("thread_time", Time); win.put("thread_text", Content); list.add(win); } } return list; } 然后调入到Handler handler = new Handler() { public void handleMessage(Message msg) { //具体.... }中。
我自己做的一个是论坛帖子详情,以及回帖,跟帖,而且是带分页效果的:
public class ThreadDetailsActivity extends Activity { LinearLayoutForListView list_threaddetails; Vector tag_content = new Vector(); View itemview; ImageView line, view_refresh; LinearLayout linear_image, linear_refresh, linear_post, linear_number; LinearLayout linear_title2, linear_title1; TextView btn_text, payment_tv; TextView title_authorname, title_time, title_theme, title_content; EditText reply_edit; Button btn_reply; // ------------------- final static int PROGRESS_DIALOG = 0; final static int PROGRESS_DIALOG1 = 1; final static int PROGRESS_DIALOG2 = 2; final static int PROGRESS_DIALOG3 = 3; ProgressThread progressThread; ProgressDialog progressDialog; public String url;// @@1 int state; // ------------------------------------------ private List<Map<String, Object>> data; private View loadingView; AdapterForLinearLayout adapter; private ScrollView sc; Vector keys = new Vector(); Vector names = new Vector(); private ProgressBar pbar; String buffer, tid; Vector list_buffer; String detailAuthor, Content, floor, Time; String threadContent, iContent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.forum_threaddetails); linear_image = (LinearLayout) findViewById(R.id.linear_image); sc = (ScrollView) findViewById(R.id.scroll); list_threaddetails = (LinearLayoutForListView) findViewById(R.id.list_forum_threaddetails); // title_listview = (ListView) findViewById(R.id.title_listview); view_refresh = (ImageView) findViewById(R.id.view_refresh); linear_refresh = (LinearLayout) findViewById(R.id.linear_refresh); linear_post = (LinearLayout) findViewById(R.id.linear_post); payment_tv = (TextView) findViewById(R.id.payment_tv); reply_edit = (EditText) findViewById(R.id.reply_edit); btn_reply = (Button) findViewById(R.id.btn_reply); linear_title1 = (LinearLayout) findViewById(R.id.linear_title1); linear_title2 = (LinearLayout) findViewById(R.id.linear_title2); // -----------截取数据-------------------- buffer = this.getIntent().getStringExtra("buffer"); tid = this.getIntent().getStringExtra("tid"); String authorName = CommonUtil.parseXml(buffer, "a"); String titleTime = CommonUtil.parseXml(buffer, "pt"); String titleTheme = CommonUtil.parseXml(buffer, "t"); String titleContent = CommonUtil.parseXml(buffer, "c"); common.CURRENTPAGE = 1; // ----------主题----------------------- title_authorname = (TextView) findViewById(R.id.title_authorname); title_time = (TextView) findViewById(R.id.title_time); title_theme = (TextView) findViewById(R.id.title_theme); title_content = (TextView) findViewById(R.id.title_content); title_authorname.setText(authorName); title_time.setText(titleTime); title_theme.setText(titleTheme); title_content.setText(titleContent); showDialog(PROGRESS_DIALOG); // --------------------- // 加载试图布局、 loadingView = LayoutInflater.from(this).inflate( R.layout.list_page_load, null); linear_number = (LinearLayout) loadingView .findViewById(R.id.linear_number); btn_text = (TextView) loadingView.findViewById(R.id.btn_text); btn_text.setText("更多跟帖"); pbar = (ProgressBar) loadingView.findViewById(R.id.pbar); linear_number.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { pbar.setVisibility(View.VISIBLE); linear_number .setBackgroundResource(R.drawable.football_shownumber1); btn_text.setText("更多跟帖"); btn_text.setTextColor(Color.WHITE); loadingHandler.postDelayed(new Runnable() { public void run() { list_threaddetails.removeView(loadingView); addListItem(); loadingHandler.sendEmptyMessage(0); adapter.notifyDataSetChanged(); loadingHandler.removeMessages(0);// 取消线程 } }, 1000); } }); // ----------------------------------------------- if (sc != null) { sc.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View arg0, MotionEvent arg1) { ThreadDetailsActivity.this.CloseKeyBoard(); return false; } }); } // 刷新 linear_refresh.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { CloseKeyBoard(); view_refresh.setImageResource(R.drawable.refulse1); common.CURRENTPAGE = 1; showDialog(PROGRESS_DIALOG); } }); // 返回 linear_image.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { ThreadDetailsActivity.this.finish(); } }); // 回复 btn_reply.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { CloseKeyBoard(); btn_reply.setBackgroundResource(R.drawable.chatroom_publish1); if (common.USERNAME.length() <= 0 && common.PASSWORD.length() <= 0) { new AlertDialog.Builder(ThreadDetailsActivity.this) .setTitle("提 示").setMessage("还没登陆,请立即登陆") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick( DialogInterface arg0, int arg1) { Utils.User_Login( ThreadDetailsActivity.this, PROGRESS_DIALOG1); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick( DialogInterface arg0, int arg1) { arg0.cancel(); arg0.dismiss(); } }).create().show(); } else { iContent = reply_edit.getText().toString(); if (iContent.length() <= 0) { Toast.makeText(ThreadDetailsActivity.this, "消息不能为空!", Toast.LENGTH_SHORT).show(); } else { url = common.SERVER + "/client/bbsreply.php?name=" + common.USERNAME + "&pwd=" + common.PASSWORD + "&tid=" + tid; System.out.println("@@@@~~" + url); showDialog(PROGRESS_DIALOG2); reply_edit.setText(""); } } } }); } Handler loadingHandler = new Handler() { public void handleMessage(android.os.Message msg) { // 改变适配器的数目 adapter.count = common.CURRENTPAGE * common.PAGESIZE; // 通知适配器,发现改变操作 adapter.notifyDataSetChanged(); loadingHandler.removeMessages(0); }; }; private void addPageMore() { list_threaddetails.addView(loadingView); } // 添加List元素 private void addListItem() { // common.INDEX = 0; // common.mNUM = common.CURRENTPAGE * common.PAGESIZE; common.CURRENTPAGE++; data = initValues(); adapter.addList(data); list_threaddetails.setAdapter(adapter); } protected Dialog onCreateDialog(int id) { state = id; switch (state) { case PROGRESS_DIALOG: case PROGRESS_DIALOG1: case PROGRESS_DIALOG2: case PROGRESS_DIALOG3: progressDialog = new ProgressDialog(ThreadDetailsActivity.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage("请稍后..."); progressThread = new ProgressThread(handler); progressThread.start(); return progressDialog; default: return null; } } private class ProgressThread extends Thread { // 由于Handler运行在主线程中(UI线程中),它与子线程可以通过Message对象来传递数据, Handler mHandler; ProgressThread(Handler h) { mHandler = h; } public void run() { String buffer = ""; if (state == PROGRESS_DIALOG) { url = common.SERVER + "/client/bbstopicreply.php?tid=" + tid + "&page=1&pagesize=100000&imei=587982314717858" + "&version=1.0&platform=j2me"; buffer = Http.Get(url); } else if (state == PROGRESS_DIALOG2) { keys.addElement("body"); names.addElement(iContent); buffer = Http.Post(url, keys, names); } else { buffer = Http.Get(url); } Message msg = mHandler.obtainMessage(); Bundle b = new Bundle(); b.putString("buffer", buffer); msg.setData(b); mHandler.sendMessage(msg); } } Handler handler = new Handler() { public void handleMessage(Message msg) { // 获取数据 buffer = msg.getData().getString("buffer"); removeDialog(state); if (state == PROGRESS_DIALOG) { data = initValues(); adapter.addList(data); list_threaddetails.setAdapter(adapter); view_refresh.setImageResource(R.drawable.refluts); } else if (state == PROGRESS_DIALOG1) { Utils.LoginStatus(ThreadDetailsActivity.this, buffer); } else if (state == PROGRESS_DIALOG2) { String code = CommonUtil.parseXml(buffer, "c"); if (code.equals("1")) { common.CURRENTPAGE = 1; list_threaddetails.removeView(loadingView); list_threaddetails.removeAllViews(); adapter.notifyDataSetChanged(); common.mNUM = 0; url = common.SERVER + "/client/bbstopicreply.php?tid=" + tid + "&page=1&pagesize=100000&imei=587982314717858" + "&version=1.0&platform=j2me"; showDialog(PROGRESS_DIALOG); } else if (code.equals("-1")) { Toast.makeText(ThreadDetailsActivity.this, "此用户被禁言", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(ThreadDetailsActivity.this, "未知错误", Toast.LENGTH_SHORT).show(); } } } }; private ArrayList<Map<String, Object>> initValues() { list_buffer = CommonUtil.parseXml2(buffer, "r"); adapter = new AdapterForLinearLayout(this); ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); int total = common.CURRENTPAGE * common.PAGESIZE; if (list_buffer.size() <= 0) { // return; Toast.makeText(ThreadDetailsActivity.this, "没有回复内容", Toast.LENGTH_SHORT).show(); } else { if (total < list_buffer.size()) { addPageMore(); } for (int i = (common.CURRENTPAGE - 1) * common.PAGESIZE; i < total; i++) { if (total >= list_buffer.size()) { total = list_buffer.size(); } String mContent = (String) list_buffer.elementAt(i); detailAuthor = CommonUtil.parseXml(mContent, "a"); Content = CommonUtil.parseXml(mContent, "c"); floor = CommonUtil.parseXml(mContent, "l"); Time = CommonUtil.parseXml(mContent, "rt"); Map<String, Object> win = new HashMap<String, Object>(); win.put("thread_number", floor + "楼"); win.put("thread_author", detailAuthor); win.put("thread_time", Time); win.put("thread_text", Content); list.add(win); } } return list; } /** * 定义弹出View试图 */ private View getView(int id) { LayoutInflater factory = LayoutInflater .from(ThreadDetailsActivity.this); View view = factory.inflate(id, null); return view; } // 点击Activity中的任意位置,edittext焦距消失,软键盘隐藏 public void CloseKeyBoard() { list_threaddetails.clearFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(list_threaddetails.getWindowToken(), 0); pbar.setVisibility(View.INVISIBLE); linear_number.setBackgroundResource(R.drawable.football_shownumber); btn_text.setText("更多跟帖"); btn_text.setTextColor(R.color.white); } public boolean onTouchEvent(MotionEvent event) { CloseKeyBoard(); return super.onTouchEvent(event); } }
下面这个压缩包项目只是相对应的框架形式,数据是死的
发表评论
-
不同的操作,加载更多样式不同
2018-06-06 16:24 711添加包: implementation 'com.scw ... -
列表滚动底部,自动显示发回顶部按钮
2017-08-08 16:00 581AutoScrollBackLayout 在ListVie ... -
ExpandableLinearLayout列表展开和收起功能
2017-07-17 16:10 968之前接触过几个类似的功能,展开和收起,都是自己在适配器里面 ... -
WaterDropListView实现ios7仿IOS“雨滴”拖拽的下拉刷新
2016-05-28 15:13 528WaterDropListView实现ios7下拉刷新和翻页 ... -
Listview列表滑动删除效果
2015-03-05 15:43 1495package com.ryg.slideview; ... -
点击实现 图标 晃动效果
2014-03-26 10:26 943定义Animation Animation sha ... -
下拉刷新功能
2012-03-15 15:08 2201参照别人的代码,然后根据需求,拉过来的,很实用 1。首 ... -
ListView动态分页的时候,定位滚动条的位置
2011-11-23 11:25 48781。找到每一页的最后一条数据的位置 public void ... -
Listview实现多个栏目(多个标题+每个标题下的内容)
2011-11-02 12:11 13610http://qsyz2002.blog.163.com/b ... -
ListView-自动加载数据一点代码
2011-10-26 15:37 1709private List<Map<String, ... -
设置ListView每个item点击背景图片设置
2011-10-26 15:31 7736利用itemview,fire,line来 ... -
ExpandableListView基本需要
2011-10-26 15:26 1403展开 int groupCount = viewAdapte ... -
ListView--BaseAdapter
2011-10-09 17:07 975自定义Adapter继承BaseAdapter http:// ... -
ListView的动态加载-很简单的Demo
2011-10-08 10:01 8033ListView的动态加载,想必大家在网上都看过很多资料了。我 ...
相关推荐
在某些场景下,例如数据量较小、不需要滚动或者只需要简单的布局时,我们可以考虑使用LinearLayout代替ListView。具体步骤如下: 1. 创建布局文件:为每个列表项创建一个单独的XML布局文件,包含所需元素。 2. 动态...
3. **使用LinearLayout代替ScrollView**:如果ListView下方还有其他内容,可以考虑使用LinearLayout作为容器,然后为LinearLayout设置垂直方向的weight属性,使ListView占据足够的空间。 4. **使用...
然而,需要注意的是,对于大型数据集,使用RecyclerView代替ListView会更高效,因为它提供了更好的滚动性能和内存管理。不过,对于小型表格,ListView已经足够满足需求。在实际开发中,根据项目需求选择合适的组件是...
5. **使用CardView或LinearLayout代替ScrollView**:如果内容不多,可以考虑使用CardView或者LinearLayout来替代ScrollView,这样可以直接将多个CardView或LinearLayout放在ListView中,避免滑动冲突。 6. **优化...
6. **使用高效的布局**:减少嵌套布局,选择性能较好的布局,如LinearLayout、RecyclerView(代替ListView)等。 7. **滚动监听**:通过实现`OnScrollListener`,可以在滚动过程中暂停不必要的后台任务,如数据刷新...
不过,考虑到现代Android开发的趋势,使用RecyclerView代替ListView可能是更好的选择,因为它提供了更强大的功能,如嵌套滚动、动画支持等。但无论选择哪种方法,都需要充分理解其工作原理,才能有效地应对复杂的...
在这个场景中,开发者选择了ScrollView加上LinearLayout来代替ListView来实现下拉刷新和加载更多的功能。 首先,我们来分析一下为什么不用ListView: 1. **ListView的复用机制**:ListView通过convertView重用机制...
另外,对于子ListView,如果内容较少,可以考虑使用LinearLayout或者其他布局代替,以减少复杂度。 在“美团嵌套listview”项目中,开发者KJY已经实现了80%的相似度,这包括了基本的嵌套布局、下拉刷新和加载更多...
- 使用ExpandableListView代替ListView也可以方便地实现这一功能,但这里我们讨论的是基于普通ListView的实现。 4. **自定义视图**: - 在`getView()`方法中,为一级列表项创建布局,包含图标、标题和一个可点击...
如果你想要优化`CardView`在`ListView`中的滑动流畅性,更建议优化`ListView`的滚动性能,比如使用`RecyclerView`代替`ListView`,或者使用`ViewHolder`模式减少视图的创建和复用。 总的来说,`CardView`和`...
如果ScrollView中的内容可以拆分成多个部分,考虑将ListView独立出来,使用多个LinearLayout或RelativeLayout来代替ScrollView。 4. 自定义滚动逻辑:如果以上方法都无法满足需求,可以尝试自定义滚动逻辑。通过...
- 使用RecyclerView代替ListView,因为RecyclerView有更高效的视图复用机制。 - 在必要时使用NestedScrollView,而不是直接在ScrollView中嵌套其他可滚动视图。 - 使用滚动事件拦截,避免不必要的滚动操作。 总结,...
解决这个问题的一种常见方法是使用`NestedScrollView`代替ScrollView,因为NestedScrollView支持嵌套滚动,它可以与另一个可滚动的视图协同工作。 ```xml android:layout_width="match_parent" android:layout_...
通常,我们可以使用LinearLayout或TableLayout作为ListView项的基础布局。TableLayout允许我们创建行和列,并通过TableRow添加单元格。每个单元格可以是TextView或其他视图,以显示数据。 ```java @Override public...
同时,持续关注Android的新特性和最佳实践,如使用RecyclerView代替ListView,以及探索更现代的布局管理器,比如GridLayoutManager,以提高应用的性能和用户体验。 总结来说,遇到ListView或GridView的`onmeasure`...
为了提高性能,可以使用SparseArray代替ArrayList存储数据,因为SparseArray对于查找操作更高效。此外,适配器中应重写getCount()、getItem()和getItemId()方法,以配合ListView的工作。 7. **视觉效果**: 为了...
为此,可以考虑使用`RecycleView`代替`ListView`,并利用其缓存机制来提高性能。此外,对适配器和视图复用策略的精细调整也是必要的。 总结一下,`CircleList`是Android开发中的一个创新实践,它通过将列表呈现在...
在Android开发中,ListView是一种常用的组件,用于展示可滚动的列表数据。...在现代Android开发中,通常推荐使用RecyclerView及其灵活的LayoutManager来代替ListView,以获得更好的性能和定制能力。
几乎没有用到,我们完全可以用LinearLayout和RelativeLayout来代替TableLayout的使用,自己开发中主要使用LinearLayout,RelativeLayout这两种布局,不过刚开始我还是偏爱于RelativeLayout,因为在RelativeLayout...