是否可以将一个视图用作另一个视图的背景?
Is possible to use one View like background to another View?
我有两个自定义通告 ProgressBar
和 TextView
。我需要将它添加到一个 View
中。喜欢 TextView
对 ProgressBar
对 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" />
所以你的问题是关于将你所有的观点都放在另一个之上(所以在一个地方)?
当然可以,尝试使用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>
我有两个自定义通告 ProgressBar
和 TextView
。我需要将它添加到一个 View
中。喜欢 TextView
对 ProgressBar
对 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" />
所以你的问题是关于将你所有的观点都放在另一个之上(所以在一个地方)?
当然可以,尝试使用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>