关于LayoutParams的使用经验

//配置文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

     <android.support.v4.view.ViewPager" />

     <LinearLayout
        android:id="@+id/ll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="24.0dip"
        android:orientation="horizontal"  
        android:visibility="gone"  >
 
        
    </LinearLayout>
</RelativeLayout>

    在界面引导的是需要用到ViewPager,一般页面引导也就是初次的时候展示,第二次我们不想要它出现,怎么办呢,

方法有二:1:简单设置隐藏setVisibility(View.GONE)

                        2:修改布局参数LayoutParams,布局参数官方文档描述是最详细的,我自己弄啦一下开始错啦。

原来这个参数是相对于Parent的,比如,上面这个配置文件中我们要修改LinearLayout的高度和宽度,那么我们应该设置

LinearLayout的布局参数由包裹他得父类布局给予,这就等于说,作为父类空间,我要给你子类在我的空间显示多大,而不是你要多大就多大。所以这个LayoutParams的类型就是RelativeLayout.LayoutParams。

LinearLayout ll=(LinearLayout) findViewById(R.id.ll);

//RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

//ll.setLayoutParams(params);

 

ll.setVisibility(View.VISIBLE);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值