最近这个项目要求读取新闻,或者审批投递。显示却要像网页一样。
说白了就是左侧的标题和右侧的内容一一对应的gridview的格式显示。
安卓才看了10多天而已。苦苦折磨,没有做出一个好效果。
后来想想,是不是可以用和C#一样的girdview来显示。
但是手机不能像电脑一样设置明显的边框。
找了一些解决方案,不是十分满意。最后有了一个自我感觉可以的办法。
效果图:
原理其实就是利用gridview的表项和背景颜色的不同,来造成边框的样子。
具体代码如下:
<!-- spdetailitem->
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#55FFFFFF"> <TextView android:id="@+id/title" android:layout_width="102dp" android:layout_height="wrap_content" android:layout_margin="10dp" android:padding="5px" android:textColor="#000000" /> <TextView android:paddingLeft="6dip" android:textColor="#000000" android:text="hahaha" android:id="@+id/detail" android:layout_width="141dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/title" android:layout_margin="10dp" android:padding="5px" /> </RelativeLayout>
<!-- spdetail->
<GridView android:id="@+id/gridView1" android:horizontalSpacing="5dp" android:verticalSpacing="5dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.53" android:numColumns="1" > </GridView>
private String[] text = { "申请事项", "申请时间", "申请人", "当前状态", "详细信息", "审核意见" }; final Sps sp = (Sps)getIntent().getSerializableExtra("sp");//用户邮件的类的对象 String[] spIn ={sp.getTitle(),sp.getUptime(),sp.getUpname(),sp.getState(),sp.getUpdetail(),sp.getSPadvice()}; GridView gridview = (GridView) findViewById(R.id.gridView1); ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>(); for (int i = 0; i < 6; i++) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("text", text[i]); map.put("sp", spIn[i]); list.add(map); } SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, R.layout.spdetailitem, new String[] { "text","sp" }, new int[] { R.id.title, R.id.detail }); // 设置GridView的适配器为新建的simpleAdapter gridview.setAdapter(simpleAdapter);