您的位置:首页 > 其它

扣丁学堂——布局性能优化(Hierarchy Viewer工具)

2016-01-29 10:16 369 查看
一丶课程讲解































本节主要源码

xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@android:color/holo_blue_dark">
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout="@layout/inc"
            android:inflatedId="@+id/stub_import"
            android:id="@+id/stub_import"
            />
        <include layout="@layout/title_bar"/>
    </LinearLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/listView" />
</LinearLayout>

MainActivity·

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private ImageView iv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = (ImageView) findViewById(R.id.imageView);
        iv.setOnClickListener(this);
        ListView lv = (ListView) findViewById(R.id.listView);

        ArrayList<HashMap<String,String>> list = new ArrayList<>();
        for (int i=1;i<20;i++){
            HashMap<String,String> map = new HashMap<>();
            map.put("title","title-"+i);
            map.put("content","content-"+i);
            list.add(map);
        }
        SimpleAdapter simpleAdapter = new SimpleAdapter(this,list,R.layout.item_layout2,new String[]{"title","content"},new int[]{R.id.textView_title,R.id.textView2_content});
        lv.setAdapter(simpleAdapter);
    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.imageView){
            ViewStub vs =(ViewStub)findViewById(R.id.stub_import);
            vs.setVisibility(View.VISIBLE);

            //
//            View v  = vs.inflate();

        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: