继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Android 自定义控件 动态设置高度

汪汪一只猫
关注TA
已关注
手记 426
粉丝 129
获赞 715

自定义控件的xml如下    <?xml version="1.0" encoding="utf-8"?>  <!-- 磁贴的大小随屏幕设置-->  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="match... TextView
       android:textSize="
       android:layout_height=".com/apk/res/android" target="_blank">http;false"TextView
       android:layout_width="
       android:text="?xml version="match_parent"1;1"://schemas:singleLine="false".com/apk/res/android"this is the text part:orientation=":gravity="
   android;vertical">:layout_weight="
   android;
<:editable=":textSize="
       android:editable="this is the text part:layout_width=".0"3"
       android.android.android;false"


解决方法:


Android动态改变View控件大小的方法:
1、声明控件参数获取对象 LayoutParams lp;
2、获取控件参数: lp = 控件id.getLayoutParams();
3、设置控件参数:如高度。   lp.height -= 10;
4:、使设置生效:控件id.setLayoutParams(lp);
例如如要把Imageview下移200px:            ImageView.setPadding( ImageView.getPaddingLeft(),  ImageView.getPaddingTop()+200,  ImageView.getPaddingRight(),  ImageView.getPaddingBottom());

原文链接:http://www.apkbus.com/blog-914653-68393.html

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP