百分比布局中的与GridView

来源:互联网 发布:单词朗读软件 知乎 编辑:程序博客网 时间:2024/06/07 06:36

在百分比布局(其他布局也行)中添加列表建议使用GridView 

如果用listview的话过于繁琐

public class MyNews extends Activity {    private GridView gview;    private List<Map<String, Object>> data_list;    private SimpleAdapter sim_adapter;    // 图片封装为一个数组    private int[] icon = { R.mipmap.ic_launcher,  R.mipmap.ic_launcher,            R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher,            R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher,            R.mipmap.ic_launcher, R.mipmap.ic_launcher };    private String[] iconName = { "第一个", "第二个", "第三个", "第四个", "第五个", "第六个", "第七个",            "第八个", "第九个", "第十个" };    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.bai_fen);        gview = (GridView) findViewById(R.id.bai_gv);        //新建List        data_list = new ArrayList<Map<String, Object>>();        //获取数据        getData();        //新建适配器        String [] from ={"image","text"};        int [] to = {R.id.image,R.id.tvId};        sim_adapter = new SimpleAdapter(this, data_list, R.layout.listview_item, from, to);        //配置适配器        gview.setAdapter(sim_adapter);    }    public List<Map<String, Object>> getData(){        //cion和iconName的长度是相同的,这里任选其一都可以        for(int i=0;i<icon.length;i++){            Map<String, Object> map = new HashMap<String, Object>();            map.put("image", icon[i]);            map.put("text", iconName[i]);            data_list.add(map);        }        return data_list;    }



<?xml version="1.0" encoding="utf-8"?><android.support.percent.PercentFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:clickable="true">    <android.support.percent.PercentFrameLayout        android:layout_width="0dp"        android:layout_height="0dp"        android:layout_gravity="top"        android:background="#ffffff"        app:layout_heightPercent="26%"        app:layout_widthPercent="100%">        <android.support.percent.PercentFrameLayout            android:layout_width="0dp"            android:layout_height="0dp"            android:layout_gravity="top"            android:background="#ffffff"            app:layout_heightPercent="50%"            app:layout_widthPercent="100%">            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_gravity="center"                android:text="2016年信和大金融员工奖励标准调整通知"                android:textColor="#ff0000"                android:textSize="15dp" />            <ImageView                android:layout_width="0dp"                android:layout_height="0dp"                android:layout_gravity="left|top"                android:src="@mipmap/tback"                app:layout_heightPercent="100%"                app:layout_widthPercent="13%" />            <ImageView                android:layout_width="0dp"                android:layout_height="0dp"                android:layout_gravity="center|left"                android:src="@mipmap/tlook"                app:layout_heightPercent="50%"                app:layout_widthPercent="13%" />        </android.support.percent.PercentFrameLayout>        <android.support.percent.PercentFrameLayout            android:layout_width="0dp"            android:layout_height="0dp"            android:layout_gravity="bottom"            android:background="#f8f8f8"            app:layout_heightPercent="50%"            app:layout_widthPercent="100%">            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:gravity="left|center"                android:paddingLeft="25dp"                android:text="专项活动"                android:textColor="#000000"                android:textSize="25dp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_gravity="right|center"                android:paddingRight="25dp"                android:src="@mipmap/more" />        </android.support.percent.PercentFrameLayout>    </android.support.percent.PercentFrameLayout>    <android.support.percent.PercentFrameLayout        android:layout_width="0dp"        android:layout_height="0dp"        android:layout_gravity="top"        android:background="#ffffff"        app:layout_heightPercent="54%"        app:layout_marginTopPercent="26%"        app:layout_widthPercent="100%">        <GridView            android:id="@+id/bai_gv"            android:layout_width="wrap_content"            android:layout_height="match_parent">        </GridView>    </android.support.percent.PercentFrameLayout></android.support.percent.PercentFrameLayout>

0 0
原创粉丝点击