Android If you do a tabular form with a ListView

Source: Internet
Author: User

:



To write like this:

@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.test); ListView list = (ListView) Findviewbyid (R.id.lvlinks); Squareitemadapter adapter = new Squareitemadapter (this); List.setdivider (null); List.setadapter (adapter);} Private class Squareitemadapter extends Baseadapter {context context; TextView tvname;public int GetCount () {//TODO auto-generated method Stubreturn 3;} Public Object getItem (int position) {//TODO auto-generated method Stubreturn position;} public long getitemid (int position) {//TODO auto-generated method Stubreturn position;} Public View GetView (int position, View Convertview, ViewGroup parent) {//TODO auto-generated method Stubfinal Layoutinfla ter Inflater = (layoutinflater) context.getsystemservice (Context.layout_inflater_service); final View v = Inflater.inflate (R.layout.square_item_view, null); tvname = (TextView) V.findviewbyid (r.id.tvitemname); if (position = = 0) {tvname.settext (getString (r.string.link_lOokaround)); V.setbackgroundresource (r.drawable.circle_list_top);} else if (position = = 1) {Tvname.settext (getString (r.string.link_recommend)); V.setbackgroundresource ( R.drawable.circle_list_middle);} else {tvname.settext (getString (R.string.link_hot)); V.setbackgroundresource (R.drawable.circle_list_bottom);} return v;} Public squareitemadapter (Context ct) {context = ct;}}

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayoutxmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" 10DP "><textviewandroid:id=" @+id/ Tvitemname "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Android:layout_ Alignparentleft= "true" android:layout_centervertical= "true" android:layout_marginleft= "18DP" style= "@style/ Userinfo_panel_textview_title "/><imageviewandroid:layout_width=" wrap_content "android:layout_height=" wrap _content "android:src=" @drawable/triangle "android:layout_alignparentright=" true "android:layout_marginright=" 18DP "android:layout_centervertical=" true "/></relativelayout>

<style name= "Userinfo_panel_textview_title" >        <item name= "Android:textsize" >16sp</item>        <item name= "Android:textcolor" > @color/user_info_name_text</item>        <item name= "Android: Duplicateparentstate ">true</item>    </style>


If you do a picture of the effect:



You can write layout like this:

<?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=" fill_parent "> <relativelayout an Droid:layout_width= "Fill_parent" android:layout_height= "130DP" android:layout_marginleft= "10DP" Andro id:layout_marginright= "10DP" android:layout_margintop= "14DP" > <view android:id= "@+id/vvdiv Ider1 "android:layout_width=" 0DP "android:layout_height=" Fill_parent "android:layout_cent Erhorizontal= "true"/> <view android:id= "@+id/vhdivider2" android:layout_width= "Fill_pa Rent "android:layout_height=" 0DP "android:layout_centervertical=" true "/> <relativelayo UT android:id= "@+id/llattention" android:layout_width= "Wrap_content" Android:layout_heigh T= "Wrap_content" Android: layout_above= "@id/vhdivider2" android:layout_alignparentleft= "true" android:layout_alignparenttop= "            True "android:layout_toleftof=" @id/vvdivider1 "android:background=" @drawable/bg_panel_above_left "                Android:clickable= "true" > <textview android:id= "@+id/tvattention_count" style= "@style/userinfo_panel_textview_count" android:layout_width= "Fill_parent" Andro id:layout_height= "Wrap_content" android:layout_centerhorizontal= "true" Android:layout_margin                top= "10DP" android:gravity= "center" android:text= "0"/> <textview Android:id= "@+id/tvattention" style= "@style/userinfo_panel_textview_title" Android:lay Out_width= "Fill_parent" android:layout_height= "wrap_content" android:layout_below= "@id/tvatt           Ention_count "     Android:layout_centerhorizontal= "true" android:gravity= "center" android:text= "Buddy list"/&G        T </RelativeLayout> <linearlayout android:id= "@+id/rlweibo" android:layout_width= "wrap _content "android:layout_height=" wrap_content "android:layout_above=" @id/vhdivider2 "Android Oid:layout_alignparentright= "true" android:layout_alignparenttop= "true" android:layout_torightof= "@i            D/vvdivider1 "android:background=" @drawable/bg_panel_above_right "android:clickable=" true "                android:orientation= "vertical" > <textview android:id= "@+id/tvweibo_count" style= "@style/userinfo_panel_textview_count" android:layout_width= "Fill_parent" Android:la yout_height= "Wrap_content" android:layout_gravity= "Center_horizontal" Android:layout_margint     op= "10DP"           android:gravity= "center" android:text= "0"/> <textview android:i D= "@+id/tvtopic" style= "@style/userinfo_panel_textview_title" android:layout_width= "Fill_par                Ent "android:layout_height=" wrap_content "android:layout_gravity=" Center_horizontal " android:gravity= "center" android:text= "Strangers list"/> </LinearLayout> <linearl Ayout android:id= "@+id/llfans" android:layout_width= "Wrap_content" android:layout_height=            "Wrap_content" android:layout_alignparentbottom= "true" android:layout_alignparentleft= "true" android:layout_below= "@id/vhdivider2" android:layout_toleftof= "@id/vvdivider1" Android:backgroun            d= "@drawable/bg_panel_below_left" android:clickable= "true" android:orientation= "vertical" >      <textview          Android:id= "@+id/tvfans_count" style= "@style/userinfo_panel_textview_count" Androi D:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:layout_gravity= "ce Nter_horizontal "android:layout_margintop=" 10DP "android:gravity=" center "and roid:text= "0"/> <textview android:id= "@+id/tvfans" style= "@style/userinfo_ Panel_textview_title "android:layout_width=" fill_parent "android:layout_height=" wrap_content "Android:layout_gravity=" center_horizontal "android:gravity=" Center "Android : text= "classmate List"/> </LinearLayout> <linearlayout android:id= "@+id/lltopic" an Droid:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_alignparentbot Tom= "true" anDroid:layout_alignparentright= "true" android:layout_below= "@id/vhdivider2" android:layout_torightof=            "@id/vvdivider1" android:background= "@drawable/bg_panel_below_right" android:clickable= "true"                android:orientation= "vertical" > <textview android:id= "@+id/tvtopic_count" style= "@style/userinfo_panel_textview_count" android:layout_width= "Fill_parent" Android : layout_height= "wrap_content" android:layout_gravity= "Center_horizontal" Android:layout_marg                intop= "10DP" android:gravity= "center" android:text= "0"/> <textview Android:id= "@+id/tvtopic" style= "@style/userinfo_panel_textview_title" android:layou T_width= "Fill_parent" android:layout_height= "wrap_content" android:layout_gravity= "Center_ho               Rizontal " android:gravity= "Center" android:text= "colleagues list"/> </LinearLayout> </RelativeLayout> </LinearLayout>


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

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.