---
title: "关于LayoutParams的使用经验"
author: "xjw1987524"
date: "2014-03-30T12:24:06Z"
tags: []
categories: ["移动开发"]
slug: "layoutparams"
draft: false
lastmod: "2014-03-30T12:24:06Z"
id: 2038474
url: "https://fishlovefly.iteye.com/blog/2038474"
---

```
//配置文件
<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);