This section describes the positional relationships in ListView and the application of LayoutAnimation in listview.

Source: Internet
Author: User
Tags xml attribute

This section describes the positional relationships in ListView and the application of LayoutAnimation in listview.

ListView attributes:

1. the XML Attribute android: divider of ListView // drawable or colorandroid: dividerHeight displayed between list entries // specifies the divider height android: entries // references the array resource that constitutes the ListView. For some fixed resources, this attribute provides a simpler way than adding resources to a program. android: footerDividersEnabled // when set to false, listView will not draw divider between each footer. the default value is true. Android: headerDividersEnabled // when set to false, ListView will not draw divider between headers. The default value is true. 2. the XML property android: cacheColorHint inherited from AbsListView // indicates that the background of this list is always drawn in a single, fixed color, and the painting process can be optimized. Android: choiceMode // specify the selected behavior for the view. Optional types: none, singleChoice, multipleChoice, and multipleChoiceModal. Android: drawselectid top // if it is set to true, the selector is drawn on the upper layer of the selected entry. The default value is false. Android: faseScrollEnabled // you can specify whether to use the quick scroll slider. Android: listSelector // sets the printable object displayed in the selected item, which can be an image or color attribute. Android: scrollingCache // sets whether to use the painting Cache during scrolling. If it is set to true, the scrolling performance is faster, but the memory usage is higher. The default value is true. Android: smoothScrollbar // if it is true, the list uses a more precise calculation method based on the visible pixel height of entries on the screen. This property is true by default. If your adapter needs to draw a variable high entry, it should be set to false. When this attribute is true, when the adapter displays a higher entry, the knob of the scroll bar changes the size during scrolling. When set to false, the list uses only the number of entries in the adapter and the visible entries on the screen to determine the attributes of the scroll bar. Android: stackFromBottom // sets whether the content of the GridView and ListView is displayed from the bottom. Android: textFilterEnabled // when it is set to true, the list filters the result to the user type. The premise is that the list Adapter must support the Filterable interface. Android: transcriptMode // sets the transcriptMode in the list. optional options: // (1) Disable TranscriptMode with disabled, which is also the default value; // (2) normal when a new entry is added to the List and is ready for display, the list will automatically slide to the bottom to display the latest entries; // (3) the alwaysScroll list will automatically slide to the bottom, regardless of whether the new entries are ready for display.

Example:

<ListView        android:layout_below="@id/btn"        android:id="@+id/draggable_list"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_centerInParent="true"        android:layout_marginBottom="5dip"        android:cacheColorHint="#f4f4f4"        android:fadingEdge="none"        android:listSelector="#f4f4f4"        android:paddingLeft="16dip"        android:paddingRight="16dip"        android:transcriptMode="alwaysScroll"        android:layoutAnimation="@anim/layout_bottom_to_top_slide" />


layout_bottom_to_top_slide

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"        android:delay="30%"        android:animation="@anim/slide_right" /><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">    <translate android:fromXDelta="-100%p" android:toXDelta="0"            android:duration="@android:integer/config_shortAnimTime" /></set>

A small example shows the positional relationship between items in listview:

Public class MainActivity extends Activity {private ArrayList <String> myList = new ArrayList <String> (); private ArrayAdapter <String> myAdapter; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); final ListView list = (ListView) findViewById (R. id. draggable_list); myList. add ("11"); myList. add ("22"); myList. add ("33"); myList. Add ("44"); myList. add ("55"); myList. add ("66"); myList. add ("77"); myAdapter = new ArrayAdapter <String> (this, android. r. layout. simple_dropdown_item_1line, myList); LayoutInflater inflater = LayoutInflater. from (this); TextView header = (TextView) inflater. inflate (R. layout. header, null); TextView footer = (TextView) inflater. inflate (R. layout. footer, null); list. addFooterView (footer); list. setOnTouchListener (new OnTouchListener () {@ Overridepublic boolean onTouch (View v, MotionEvent event) {float x = event. getX (); float y = event. getY (); print (list, x, y); return false ;}}); list. addHeaderView (header); list. setAdapter (myAdapter); Button btn = (Button) findViewById (R. id. btn); btn. setOnClickListener (new View. onClickListener () {@ Overridepublic void onClick (View v) {myList. add ("88"); myList. add ("99"); myList. add ("aa"); myA Dapter. notifyDataSetChanged () ;}});} private void print (final ListView list, final float pointerX, float pointerY) {int firstVisiblePosition = list. getFirstVisiblePosition (); // the serial number of the first listview item on the current screen. It contains the header. int lastVisiblePosition = list is calculated from 0. getLastVisiblePosition (); // the serial number of the last listview item on the current screen, including header and footer. int maxItemPosition = list is calculated from 0. getCount ()-list. getFooterViewsCount ()-1 ;// This does not include footer view, list. getCount () calculates both the header and footer into int minItemPosition = list. getHeaderViewsCount (); // here beginViewIndex refers to the item (excluding headerview) int beginViewIndex = (firstVisiblePosition> minItemPosition? FirstVisiblePosition: minItemPosition)-firstVisiblePosition; // The endViewIndex here does not contain the footer view. The int endViewIndex = (lastVisiblePosition <maxItemPosition? LastVisiblePosition: maxItemPosition)-firstVisiblePosition; // This is the serial number of the clicked view on the current screen. int pointeredViewIndex = list is calculated from 0. pointToPosition (int) pointerX, (int) pointerY)-firstVisiblePosition; // This is the sequence number of the clicked view on the current screen. It starts from 0 and can be calculated through listview. getChild (pointeredViewIndex) obtains the item <span style = "white-space: pre"> </span> int pointeredItemPosition = pointeredViewIndex + firstVisiblePosition-minItemPosition; System. out. println ("==== firstVisiblePosition =" + firstVisiblePosition + "lastVisiblePosition =" + lastVisiblePosition); System. out. println ("=== beginViewIndex =" + beginViewIndex + "endViewIndex =" + endViewIndex + "maxItemPosition =" + maxItemPosition + "minItemPosition =" + minItemPosition); System. out. println ("=== pointeredViewIndex =" + pointeredViewIndex );}}

Code: http://download.csdn.net/detail/baidu_nod/7762055


How does android read the image recorded in the database in listView?

R. drawable. xxx? It is inconvenient to store the variable name. Save the value of the variable and use SimpleAdapter.
R. drawable. xxx can also create a one-to-one map in the program.

The problem of copying Listview data to another Listview in C #

Then only the FOR loop is used;
C #
Foreach (ListViewItem item in listView1.Items)
ListView2.Items. Add (ListViewItem) item. Clone ());

VB. NET
For Each item As ListViewItem In listView1.Items
ListView2.Items. Add (item. Clone ())
Next

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.