码迷,mamicode.com
首页 > 其他好文 > 详细

RelativeLayout-代码中设起成员控件width height

时间:2015-06-01 16:38:28      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

今天需要在代码中动态的设置一个textview的width跟height属性,记录下来。

textview在xml中的布局如下

 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/setup_fragment_padding_bottom_vfive"
        android:layout_marginLeft="@dimen/setup_fragment_padding_left"
        android:layout_marginRight="@dimen/setup_fragment_padding_right"
        android:background="@null"
        >

        <!-- Buttons below -->
            <!--
        In order to show these buttons above the IME keyboard, we need to special case the to
        padding to a smaller height.
            -->
        <TextView
            android:id="@+id/previous"
            style="@style/accountSetupButtonVfive"
            android:layout_width="159dp"
            android:layout_height="wrap_content"
            android:background="@drawable/email_btn_set"
            android:layout_centerVertical="true"
            android:text="@string/previous" />
        <TextView
            android:id="@+id/manual_setup"
            style="@style/accountSetupButtonVfive"
            android:layout_width="159dp"
            android:layout_height="wrap_content"
            android:background="@drawable/email_btn_set"
            android:layout_centerVertical="true"
            android:visibility="gone"
            android:text="@string/account_setup_basics_manual_setup_action" />

        <TextView
            android:id="@+id/next"
            style="@style/accountSetupButtonVfive"
            android:layout_width="159dp"
            android:layout_height="wrap_content"
            android:background="@drawable/email_btn_next"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="@string/next" />
    </RelativeLayout>

 

 

在代码中的更改如下

import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

        if (visibility == View.GONE) {
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
            mPreviousButton.setBackgroundResource(R.drawable.email_btn_previous_only);
            mPreviousButton.setLayoutParams(lp);
        }

注意,如果这个控件的layout是LinearLayout,那么你需要使用相应的LinearLayout.LayoutParams

RelativeLayout-代码中设起成员控件width height

标签:

原文地址:http://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_python_156155.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!