Android、如何动态加载View的高度

ViewGroup.LayoutParams params            在网上找了很多教程。按照如下方法写:

           

<strong>LinearLayout.LayoutParams imagebtn_params = newLinearLayout.LayoutParams(

                  LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

              imagebtn_params.height = dm.widthPixels / 4;

              imagebtn_params.width = dm.widthPixels / 4;

             imagebtn.setLayoutParams(imagebtn_params);</strong>


这里参见 http://blog.csdn.net/pathuang68/article/details/6647716  但是我发现View的高度并没有改变。

而我的布局文件比之是更加复杂的,如下
<strong><TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
	<FrameLayout
    		android:id="@+id/SheduleTitle"
    		android:layout_width="10dp"
    		android:layout_height="10dp"
    		android:background="@android:color/black">
    		<TabWidget 
       			android:id="@android:id/tabs"
       			android:layout_width="fill_parent"
       			android:layout_height="9dp"
       			android:visibility="gone" />
   			<RadioGroup 
   			    android:layout_width="wrap_content"
   			    android:layout_height="wrap_content"
   			    android:orientation="horizontal"
   			    android:id="@+id/SheduleGroup"
   			    >
   			    <RadioButton 
   			        android:layout_width="wrap_content"
   			        android:layout_height="wrap_content"
   			        android:id="@+id/SheduleButton"
   			        />
   			    <RadioButton 
   			        android:layout_width="wrap_content"
   			        android:layout_height="wrap_content"
   			        android:id="@+id/SheduleMore"
   			        android:background="@android:color/white"
   			        />
   			    <RadioButton 
   			        android:layout_width="wrap_content"
   			        android:layout_height="wrap_content"
   			        android:id="@+id/SheduleImfor"
   			        android:background="@android:color/black"
   			        />
   			</RadioGroup>
		</FrameLayout>
		<FrameLayout
       	android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="0.0dip"
        android:layout_weight="1.0" >
		</FrameLayout>
</TabHost>
</strong>
我现在想改变的是FrameLayout的高度。
如这里参考的,我发现是   setContentView(R.id.xx),而官方文档 setContentView(View view),setContentView(View view,  ViewGroup.LayoutParams  params)。
在 inflater 获得整个View以后,我再用前面所参考的方法设置FrameLayout高度。
使用setContent(View view)方法绘图,成功改变了高度。
简单原因 : R.id.xx 是我们已经写好的xml,其中一些控件属性其已经固定不变了,而View相当于一个中间变量,我们可以改变其中的参数。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值