android 垂直方向进度条progressbar

本文介绍了如何在Android中实现垂直方向的进度条。通过修改原生水平进度条的XML资源文件,调整`clipOrientation`为垂直并改变`gravity`属性,可以创建一个自定义的垂直进度条。在布局文件中应用修改后的XML,最终展示出垂直进度条的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


在实际需求会碰到使用垂直方向的是进度条


一 水平方向进度条

1.先看看原生的水平方向进度条



<ProgressBar
        android:id="@+id/progress3"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:indeterminate="false"
        android:indeterminateOnly="false"
        android:max="100"
        android:progress="50"
        />


2.根据style="?android:attr/progressBarStyleHorizontal",我们找到源码中的style.xml


<style name="Widget.ProgressBar.Horizontal">
         <item name="android:indeterminateOnly">false</item>
         <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
         <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
         <item name="android:minHeight">20dip</item>
         <item name="android:maxHeight">20dip</item>
     </style>


3.看到<item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
木有,继续发掘源码,找到drawable下面的progress_horizontal.xml,这就是我们今天的主角

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
    
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值