View中inflate方法
来源:互联网 发布:大阪 知乎 编辑:程序博客网 时间:2024/06/03 19:58
View headView = View.inflate(this,R.layout.item2,null);
View headView = LayoutInflater.from(this).inflate(R.layout.item_head,listView1,false);
View headView = LayoutInflater.from(this).inflate(R.layout.item_head,listView1,false);
大家都知道如果用第二种方法填充条目,子 item 可以自己决定自己自身大小,但是第二种方法想让子 item 就不能决定自身的大小了。如果想要
在父布局中展现子 item 的大小,就要在子 item 外面套一层布局。如想要把一张图片()当作 listview 的头部:
<?xml version="1.0" encoding="utf-8"?>
第一种布局:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/iv"
android:layout_width="match_parent"
android:layout_height="160dp"
android:orientation="vertical"
android:src="@mipmap/ic_launcher_round"
>
</ImageView>
在父布局中展现子 item 的大小,就要在子 item 外面套一层布局。如想要把一张图片()当作 listview 的头部:
<?xml version="1.0" encoding="utf-8"?>
第一种布局:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/iv"
android:layout_width="match_parent"
android:layout_height="160dp"
android:orientation="vertical"
android:src="@mipmap/ic_launcher_round"
>
</ImageView>
第二种布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:id="@+id/iv"
android:src="@mipmap/ic_launcher_round"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:id="@+id/iv"
android:src="@mipmap/ic_launcher_round"
/>
</LinearLayout>
第二种布局 ImageView 就可以展示自己原有的大小,第一种布局,在父布局中的宽高是 wrap_content。
阅读全文
1 0
- View中inflate方法
- Android中View.inflate()
- ndroid中View.inflate()
- LayoutInflater.inflate方法加载View
- View inflate 方法与 LayoutInflater inflate 方法的区别详解
- View.inflate和LayoutInflater的inflate方法区别
- (转)View.inflate和LayoutInflater的inflate方法区别
- inflate获取view 的几种方法
- Android中通过inflate构建一个View
- LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)
- LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)
- LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)
- LayoutInflater中inflate方法详解
- Android:inflate.inflate()方法
- View类的方法inflate和LayoutInflater类的inflate方法
- [Android] 一种优化view inflate耗时的方法
- Android中inflate方法的用法
- Android中inflate方法的用法总结
- 并查集奇妙应用-机房模拟赛某题-同BZOJ4569
- operator运算符的重载问题
- java 泛型
- eclipse配置server locations及工程发布后文件位置总结
- Mybatis 之 ResultSetHandler
- View中inflate方法
- Python的方法解析顺序(MRO)
- SPOJ NSUBSTR Substrings
- bzoj3991 [SDOI2015]寻宝游戏 (虚树+set+dfs序 )
- 加帕里的聚会 (树链剖分 双标记线段树)
- 理解HTTP幂等性
- mac查看进程
- bzoj 2257: [Jsoi2009]瓶子和燃料
- selenium 基于python学习笔记---【3-2】