gpt4 book ai didi

Android ProgressBar UI 自定义布局

转载 作者:IT王子 更新时间:2023-10-28 23:30:17 25 4
gpt4 key购买 nike

我正在尝试自定义状态栏,使其看起来像这样的图像:enter image description here

然而,几个小时后,我所拥有的只是一个带有我需要的背景的状态栏(图 2):enter image description here

我目前的代码是:xml布局:

<ProgressBar
android:id="@+id/pBarOverallStatus"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_weight="94"
android:indeterminateOnly="false"
android:max="100"
android:progressDrawable="@drawable/progress_bar_states" >
</ProgressBar>

progress_bar_states.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- <item android:id="@android:id/progress">
<bitmap
android:gravity="center"
android:src="@drawable/progressbar_progressing" />

<corners android:radius="10dp" />
</item>
-->

</layer-list>

删除评论,其中 proressbar_progressing 看起来像 enter image description here然后我有点难看,因为没有角落。 enter image description here

我正在从代码中添加背景,例如:

overallStatus = (ProgressBar) findViewById(R.id.pBarOverallStatus);
Resources res = getResources();
overallStatus.setBackgroundDrawable(res.getDrawable(R.drawable.progressbar_background));
overallStatus.setProgress(50);

我尝试为图像添加角,但没有成功。有人知道我在这里做错了什么吗?或者我错过了什么?另外,您知道如何添加左右环吗?资源: enter image description here

最佳答案

解决方案(回答你自己的感觉很奇怪):首先,一个问题是进度可绘制的大小与背景不同(愚蠢的我!)。此外,对于可绘制的进度,需要一个剪辑 xml。类似progressbar_progress_clip.xml:

<?xml version="1.0" encoding="utf-8"?>
<clip
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progressbar_progressing"
android:clipOrientation="horizontal"
android:gravity="left"/>

然后,在相对布局中添加进度条和两张图片,以便在状态栏之后绘制图片。像这样的:

<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_weight="94" >

<ProgressBar
android:id="@+id/pBarOverallStatus"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:indeterminateOnly="false"
android:max="100"
android:progressDrawable="@drawable/progressbar_progress_clip" >
</ProgressBar>

<ImageView
android:id="@+id/ringLeft"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="7dp"
android:contentDescription="@string/status_bar_ring"
android:src="@drawable/status_bar_ring" />

<ImageView
android:id="@+id/ringRight"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="7dp"
android:contentDescription="@string/status_bar_ring"
android:src="@drawable/status_bar_ring" />
</RelativeLayout>

谢谢各位!

关于Android ProgressBar UI 自定义布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9921621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com