使EditText的宽度自动适应屏幕控件

在开发过程中涉及到EditText和其他控件在一排的时候,而且需要动态改变EditText的宽度以便让一排控件能自动适应不同的屏幕宽度,可以使用以下办法:

<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2" >
                <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/memotitle" android:id="@+id/memotitle" android:textSize="18dp"></TextView>
<EditText android:id="@+id/title_view"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:singleLine="true"
                android:editable="false"
                android:focusable="false"
                android:clickable="true"
                android:layout_weight="1"
                android:marqueeRepeatLimit="marquee_forever"/>
            <ImageView android:id="@+id/view_memo_alarm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|right"
            android:background="@drawable/ic_toolbar_alarm_m" android:focusable="false" />   
</LinearLayout>

案例中EditText和TextView以及ImageView在一排,而且根据程序的需要ImageView需要动态显示或者隐藏,通过以上的XML配置即可实现,重点在于这句话:

android:layout_weight="1"




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值