Android三个不同大小的圆圈

Android three circles different sizes

嗨,我在 android 中有 3 个圆圈显示进度,是一个自定义元素 (ViewProgressbar),继承自相对布局。

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:gravity="center">

  <com.theproject.ui.view.ViewProgressbar
  android:id="@+id/vps_history_progress1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  app:value= "@string/zero"
  app:subject = "@string/txt_progress1"
  />

  <com.theproject.ui.view.ViewProgressbar
    android:id="@+id/vps_history_progress2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:value= "@string/zero"
    app:subject = "@string/txt_progress2" 
  />

  <com.theproject.ui.view.ViewProgressbar
      android:id="@+id/vps_history_progress3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      app:value= "@string/zero"
      app:subject = "@string/txt_progress3"
  />

</LinearLayout>

我面临的问题是,在小屏幕设备中,第三个圆比其他圆小。我认为与我正在使用 wrap_content 有关。有没有办法强制三个圆圈大小相同?

谢谢

是的,有。使用 weight 属性:

 <com.theproject.ui.view.ViewProgressbar
   android:id="@+id/vps_history_progress1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
      android:layout_weight=1
   app:value= "@string/zero"
   app:subject = "@string/txt_progress1"
 />

对 LinearLayout 内的其他视图重复此操作。

用这个替换你的资源。 请注意 WeightSum 为 3,每个 child 为 1 加起来为 3。 每个 child 将水平均匀分布。

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
android:gravity="center">

<com.theproject.ui.view.ViewProgressbar
android:id="@+id/vps_history_progress1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
app:value= "@string/zero"
app:subject = "@string/txt_progress1"
/>

<com.theproject.ui.view.ViewProgressbar
android:id="@+id/vps_history_progress2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
app:value= "@string/zero"
app:subject = "@string/txt_progress2" 
/>

<com.theproject.ui.view.ViewProgressbar
android:id="@+id/vps_history_progress3"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
app:value= "@string/zero"
app:subject = "@string/txt_progress3"
/>

</LinearLayout>