【问题标题】:Use a progressbar inside a custom view?在自定义视图中使用进度条?
【发布时间】:2014-11-20 17:55:56
【问题描述】:

您好,我制作了一个自定义视图和一个 lifebarprocess.xml。我想用我画的所有其他东西在我的自定义视图中绘制救生圈。但我不知道该怎么做:

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

自定义视图(短):

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>

我的人可以提供帮助 - 提前感谢。

【问题讨论】:

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


    【解决方案1】:

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

    ViewGroup 是一个特殊的视图,可以包含其他视图(称为 孩子。)视图组是布局和视图的基类 容器。

    【讨论】:

      猜你喜欢
      • 2011-07-27
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      • 2016-05-06
      相关资源
      最近更新 更多