android - 在自定义 View 中使用进度条?

标签 android progress-bar draw android-custom-view

您好,我制作了一个自定义 View 和一个 lifebarprocess.xml。我想在我的自定义 View 中绘制 lifebar 以及我绘制的所有其他内容。但我不知道如何:

-在我的 View 中创建/引用进程栏以及我如何绘制它。 -可以更改进度条 xml 吗?

自定义 View (短):

public class Gamecontroller_View  extends View implements OnGestureListener{

private Paint mPaint;

public Gamecontroller_View(){
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setColor(Color.BLUE);
        mPaint.setMaskFilter(new BlurMaskFilter(15, Blur.OUTER));
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
}

  @Override
      protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

      if (fingerpointer != null){
          mPaint.setColor(colors[0]);
          canvas.drawCircle(fingerpointer.x, fingerpointer.y, 30, mPaint);
          }

       //I want to draw a Progressbar's current appearance here

      }

}

lifeprocessbar.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
  <item android:id="@android:id/background">
    <shape>
      <corners android:radius="5dip" />
      <gradient
        android:angle="270"
        android:centerColor="#ff5a5d5a"
        android:centerY="0.5"
        android:endColor="#ff747674"
        android:startColor="#ff9d9e9d" />
    </shape>
  </item>
  <item android:id="@android:id/progress">
    <clip>
      <shape>
        <corners android:radius="5dip" />
          <gradient
            android:angle="0"
            android:endColor="#ff0000"
            android:startColor="#ff3300" />
      </shape>
    </clip>
  </item>
</layer-list>

还有 lifebarprocess_layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


        <ProgressBar
        android:id="@+id/playerlifeprocessbar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="30dp"
        android:progress="90"
        android:progressDrawable="@drawable/lifeprocessbar" />


</LinearLayout>

我的人可以提供帮助 - 在此先感谢。

最佳答案

您可能需要考虑扩展 ViewGroup在您的 Gamecontroller_View 而不是 View 中。来自文档:

A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers.

关于android - 在自定义 View 中使用进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27046334/

相关文章:

php - 命令调用服务中的 Symfony 进度条

c# - 绘制圆时如何控制圆的大小和位置

Delphi Grid DrawColumnCell无法清除

android - 三星S8 Android 8.0的蓝牙HCI日志在哪里

java - 在按钮单击 android 上发送解析推送通知

winapi - 如何更新进度条?

python - 使用 Python Keras 训练 CNN 1D 时出现 AttributeError

qt - 如何在不旋转的情况下使用 QPainter 类围绕圆编写值?

Android 谷歌地图 - keytool 生成 SHA1 而不是 MD5 哈希

android - 将分隔线放置在 ListView 中的某个位置