Settings for the ListView split line in Android

Source: Internet
Author: User

Today we find that the split line between the ListView item on many apps shows only the right part, while the left half does not, and the first response is to set a background image for the split line OK:

android:divider= "@mipmap/line"

However, later on the Internet to find information found that you can define a drawable, set it as the ListView of the Split Line (divider)



Listview_item_divider under 1.drawable:
1 <?xml version= "1.0" encoding= "Utf-8"?>2 <inset xmlns:android= "/http Schemas.android.com/apk/res/android "3     android:insetleft=" 100DP "4     android:insetright= "15DP"5     android:drawable= "@color/line_gray" >67 </inset>

2.activity_main in the ListView:

1 <ListView23         android:id= "@+id/lv_main"4         android: divider= "@drawable/listview_item_divider"5         android:dividerheight= "1DP"6         android: Layout_width= "Match_parent"7         android:layout_height= "Match_parent" >8 </listview >

3.item layout:

1<?xml version= "1.0" encoding= "Utf-8"?>2<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"3Android:layout_width= "Match_parent"4android:layout_height= "Wrap_content"5android:orientation= "Horizontal"6android:padding= "3DP" >7 8<ImageView9Android:id= "@+id/img_item"TenAndroid:layout_width= "100DP" Oneandroid:layout_height= "100DP" Aandroid:contentdescription= "@null" -Android:scaletype= "Fitxy" -android:src= "@mipmap/octocat"/> the  -<TextView -Android:id= "@+id/tv_item" -Android:layout_width= "Match_parent" +android:layout_height= "100DP" -android:gravity= "Center" +android:text= "TITLE" AAndroid:textsize= "15SP"/> at  -</LinearLayout>

4.MainActivity (because it is relatively simple, so there is no strict code format)

1  Public classMainactivityextendsappcompatactivity {2 3     PrivateListView Mlistview;4 5 @Override6     protected voidonCreate (Bundle savedinstancestate) {7         Super. OnCreate (savedinstancestate);8 Setcontentview (r.layout.activity_main);9Mlistview =(ListView) Findviewbyid (r.id.lv_main);Ten         //set the data for the ListView (without changing the picture, just set a different title) Onelist<map<string, string>> list =NewArraylist<>(); A          for(inti = 0; I < 20; i++) { -map<string, string> map =NewHashmap<>(); -Map.put ("title", "Talon" +i); the list.add (map); -         } -Simpleadapter adapter =NewSimpleadapter ( This, List, -R.layout.listview_item,Newstring[]{"title"}, +                 New int[]{r.id.tv_item}]; - Mlistview.setadapter (adapter); +     } A}

About the bad place in the text, welcome you to criticize correct!

Settings for the ListView split line in Android

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.