【问题标题】:Is possible to use one View like background to another View?是否可以将一个视图(如背景)用于另一个视图?
【发布时间】:2015-09-17 17:45:47
【问题描述】:

我有两个自定义通知 ProgressBarTextView。我需要将它添加到一个View 中。喜欢TextViewProgressBarProgresBar
听到是我的 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" />  

【问题讨论】:

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


    【解决方案1】:

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

    当然可以,尝试使用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>
    

    【讨论】:

      猜你喜欢
      • 2013-04-03
      • 2011-04-18
      • 2015-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      相关资源
      最近更新 更多