layout_weight_权重

本文介绍了一种在Android中实现水平布局的方法,并通过设置权重属性使得进度条能够根据屏幕大小进行伸缩调整,同时保持按钮的位置不变。这种方式非常适合需要在界面上放置可伸缩组件的应用场景。
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/iv_icon"
android:orientation="horizontal"
    >

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:max="100"
        android:progress="20"
        android:layout_weight="1"
        android:layout_gravity="center"
        />
    <Button
        android:id="@+id/button_upload"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="上传"
        />
</LinearLayout>

1.
android:orientation="horizontal",水平布局 或是 垂直布局 
 在 需要 拉伸的 那个控件上 设置 
android:layout_weight="1" 就可以了



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值