关于LayoutParams的使用经验
16lz
2022-07-27
//配置文件<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);
更多相关文章
- mybatisplus的坑 insert标签insert into select无参数问题的解决
- Python技巧匿名函数、回调函数和高阶函数
- python list.sort()根据多个关键字排序的方法实现
- android Dialog大小修改
- android中文api(89)——ViewManager
- Android调用天气预报的WebService简单例子
- Android(安卓)Activity的启动
- 从 Android(安卓)Sample ApiDemos 中学习 android.animation API
- android源码下载方式