android 自定义VIew 动态在页面中改变页面的布局

首先明确这几个高度的的意义:

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进行在程序中确定视图的,因为有些情况在特定的情况下需要在页面中显示不同的内容,而这种情况就可以解决这种问题。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值