是否可以使用一个视图像背景到另一个视图?

时间:2015-09-17 17:45:48

标签: android xml view android-linearlayout android-progressbar

我有两个自定义循环ProgressBarTextView。我需要将其添加到一个View中。与TextViewProgressBar上的ProgresBar一样 听到我的XML -

<LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_weight="45"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/tvTimer"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
   <ProgressBar
        android:id="@+id/barTimer"
        style="?android:attr/progressBarStyleHorizontal"
        android:max="100"
        android:rotation="-90"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:progressDrawable="@drawable/circular_progress_bar"/>
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:max="100"
        android:progress="100"
        android:progressDrawable="@drawable/circle_progress_background" />  

1 个答案:

答案 0 :(得分:0)

所以你的问题是将你的所有观点都放在另一个之上(所以在一个地方)?

当然可以尝试使用RelativeLayout代替LinearLayout作为根布局。它允许您将一个视图与另一个视图重叠,具体取决于您将它们添加到代码中的顺序。

所以你的代码可能看起来像这样:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="45">
    <ProgressBar
        android:id="@+id/barTimer"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:max="100"
        android:rotation="-90"
        android:progressDrawable="@drawable/circular_progress_bar"/>
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:max="100"
        android:progress="100"
        android:progressDrawable="@drawable/circle_progress_background"/>
    <TextView
        android:id="@+id/tvTimer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        />
</RelativeLayout>