
XML代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Button 置底 -->
<LinearLayout android:id="@+id/test_bottom_buttons"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_alignParentBottom="true">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="确定"></Button>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="取消"></Button>
</LinearLayout>
</RelativeLayout>
接下来就是要把剩余的空间用一个ListView进行填充了。
最开始bill臆断地认为,只要在包裹Buttons的LinearLayout代码上方加上一个ListView就OK了,这是我最开始错误的xml布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/lv_test" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
<!-- Button 置底 -->
<LinearLayout android:id="@+id/test_bottom_buttons"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_alignParentBottom="true">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="确定"></Button>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="取消"></Button>
</LinearLayout>
</RelativeLayout>
WindowManager中有个添加View的函数:public void addView(View view, ViewGroup.LayoutParams params)
Window中有个添加View的函数:
public void addContentView(View view, ViewGroup.LayoutParams params)
弄清楚这两个类和这两个函数的作用设计到Android整个Surface系统,这里不详述,只作说明,供自己记录。
事实上,这两个函数是Activity上显示View至关重要的控制函数,它们在框架层已经有了明确的分工。查看这两个函数的调用过程可以发现addView的调用是针对ViewRootImpl的,也就是它添加的View相当于最底层的PhoneWindow.DecorView;而addContentView最终指向了ViewGroup.addView(childView)。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)