首先明确这几个高度的的意义:
headParams.topMargin
headParams 是MarginLayoutParams的对象,这个的意义是组件离父窗体上部的距离,就是子组件距离父组件上部的距离
自定义的View可以动态的添加布局:
<com.xushuangshuang.realpulltoreflesh.RefreshView
android:id="@+id/refreshable_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"></ListView>
</com.xushuangshuang.realpulltoreflesh.RefreshView>
首先将布局绑定到相应的类中;
layoutInflater = LayoutInflater.from(context);
headLinerLayout = layoutInflater.inflate(R.layout.pull_top, null);
pullArrow = (ImageView) headLinerLayout.findViewById(R.id.pull_arrow);
refreshingBar = (ProgressBar) headLinerLayout.findViewById(R.id.progress_bar);
statusText = (TextView) headLinerLayout.findViewById(R.id.dowan_pull_text);
timeText = (TextView) headLinerLayout.findViewById(R.id.pull_refresh_time);
initUITextValue();
setOrientation(VERTICAL);
addView(headLinerLayout, 0);
这种是将页面默认的添加到父类的页面中,这样高度和长度都是可以进行指定:
hideHeadHight = -headLinerLayout.getHeight();
headParams = (MarginLayoutParams) headLinerLayout.getLayoutParams();
headParams.topMargin = hideHeadHight;
这种就可以动态的制定了子类布局的相关的属性
第二种;
addHeaderView(headView);
直接将子类的视图添加到头的位置
headContentHeight = headView.getMeasuredHeight();
headView.setPadding(headView.getPaddingLeft(), -1 * headContentHeight,
headView.getPaddingRight(), headView.getPaddingBottom());
headView.invalidate();
动态的修改子类布局的参数
类似的还有:
addFooterView(footView, null, false);
这就是两种自定义的view进行在程序中确定视图的,因为有些情况在特定的情况下需要在页面中显示不同的内容,而这种情况就可以解决这种问题。