Java Code Examples for android.widget.ScrollView#smoothScrollTo()
The following examples show how to use
android.widget.ScrollView#smoothScrollTo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuyTicketInfoFragment.java From Huochexing12306 with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_buy_ticket_info, null); lvInfos = (ListView) v.findViewById(R.id.buyTicketInfo_lvInfos); MyDatabase myDB = new MyDatabase(this.getActivity()); mAdapter= new SimpleAdapter(this.getActivity(), mLstDatas, R.layout.item_buy_ticket_info, new String[]{MyDatabase.KEY, MyDatabase.VALUE}, new int[]{R.id.item_buy_ticket_info_tvQuestion, R.id.item_buy_ticket_info_tvAnswer} ); lvInfos.setAdapter(mAdapter); myDB.closeDB(); notifyAdapterDataChanged(myDB.getTicketInfos(0)); MyUtils.setListViewHeightBasedOnChildren(lvInfos); //设置ListView全部显示 ViewGroup.LayoutParams params = lvInfos.getLayoutParams(); params.height += 3000; //方法不太准,人为校正高度 lvInfos.setLayoutParams(params); sv1 = (ScrollView)v.findViewById(R.id.buyTicketInfo_sv1); sv1.smoothScrollTo(0, 20); return v; }
Example 2
Source File: ExpandableHeightExpandableListView.java From Bluefruit_LE_Connect_Android with MIT License | 6 votes |
public void scrollToGroup(int groupPosition, View view, ScrollView parentScrollView){ final float baseY = getY(); final float currentGroupPosY = baseY + view.getY(); final int currentScrollY = parentScrollView.getScrollY(); final View nextGroupView = findViewWithTag(groupPosition+1); if (currentScrollY > currentGroupPosY) { parentScrollView.smoothScrollTo(parentScrollView.getScrollX(), view.getTop()); } else if (nextGroupView != null) { final float nextGroupPosY = baseY + nextGroupView.getY(); if (currentScrollY + parentScrollView.getHeight() < nextGroupPosY) { parentScrollView.smoothScrollTo(0, nextGroupView.getBottom()); } } else { parentScrollView.smoothScrollTo(parentScrollView.getScrollX(), getBottom()-parentScrollView.getHeight()); } }
Example 3
Source File: NewsDetailActivity.java From Social with Apache License 2.0 | 5 votes |
private void handleCommentList(Message msg){ String result = msg.obj.toString(); Log.d("NewsDetail", result); gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); root = gson.fromJson(result, Root.class); if (root == null){ //new Dialog(this,"错误","链接服务器失败").show(); Toast.makeText(this,"服务器繁忙,请重试",Toast.LENGTH_LONG).show(); return; } if (root.success == true){ //new Dialog(this,"错误",root.message).show(); list_comment.clear(); CommentItem commentItem; for (Comment comment : root.list_comment){ commentItem = new CommentItem(); commentItem.setId(comment.id); commentItem.setTime(comment.date); commentItem.setNickname(comment.nickname); commentItem.setUsername(comment.username); commentItem.setUser_head_path(comment.user_head_path); commentItem.setContent(comment.content); commentItem.setUser_id(comment.user_id); commentItem.setComment_id(comment.comment_id); commentItem.setComment_voice(comment.comment_voice_path); list_comment.add(commentItem); } //ad = new CommentItemAdapter(this,R.layout.comment_item,list_comment); //listView.setAdapter(ad); //setListViewHeightBasedOnChildren(listView); commentItemBaseAdapter = new CommentItemBaseAdapter(this,list_comment); listView.setAdapter(commentItemBaseAdapter); CommentUtil.setListViewHeightBasedOnChildren(listView); ScrollView scrollView = (ScrollView)this.findViewById(R.id.id_news_detail_scrollview); scrollView.smoothScrollTo(0, 0); } }