【发布时间】:2018-05-16 00:58:28
【问题描述】:
我想实现一个计时器,它周围有一个圆圈,随着计时器开始计时而逐渐消失。我遇到的问题是包含进度条的片段不会缩放以适应它所在的容器并在顶部和底部切断。我感觉这是一个与高度相关的问题,因为如果我增加包含片段的容器的高度,进度条会再次按预期工作。
在这张图片中,我增加了父母的高度,并且切断问题得到了解决,但这个解决方案不适合我的目的。
这是我的 xml 文件
shape_ring_color_yellow.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="360"
android:toDegrees="0">
<shape
android:shape="ring"
android:thickness="10dp"
android:useLevel="true">
<solid android:color="@color/colorCountDownTimerYellow" />
</shape>
</rotate>
count_down_timer_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<TextView
android:id="@+id/textViewTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text=""
android:textColor="@android:color/black"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="@+id/progressBarCircle"
app:layout_constraintEnd_toEndOf="@+id/progressBarCircle"
app:layout_constraintStart_toStartOf="@+id/progressBarCircle"
app:layout_constraintTop_toTopOf="@+id/progressBarCircle" />
<ProgressBar
android:id="@+id/progressBarCircle"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:max="100"
android:progress="100"
android:progressDrawable="@drawable/shape_ring_color_yellow" />
</RelativeLayout>
使用 count_down_timer_fragment.xml 的布局的部分 XML
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bubblewall.saik.bubblewall.RemoteControlBubbleWall"
android:background="@drawable/background_gradient_color_light_blue">
<LinearLayout
android:id="@+id/linear_layout_control_buttons"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/horizontal_guideline_10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/button_on_off"
style="@style/Widget.AppCompat.Button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/button_background_gradient_green_black_border"
android:text="@string/on" />
<fragment
android:id="@+id/countDownTimerFragment"
android:name="com.bubblewall.saik.bubblewall.CountDownTimerFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:scaleType="fitCenter"
tools:layout="@layout/count_down_timer_fragment" />
<Button
android:id="@+id/button_sleep"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/button_background_gradient_yellow_black_border"
android:text="@string/sleep"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@+id/constraint_layout_sleep_button_and_timer"
app:layout_constraintEnd_toEndOf="@+id/constraint_layout_sleep_button_and_timer"
app:layout_constraintStart_toStartOf="@+id/constraint_layout_sleep_button_and_timer"
app:layout_constraintTop_toTopOf="@+id/constraint_layout_sleep_button_and_timer" />
</LinearLayout>
此时我尝试了一切。我尝试将布局重力设置为中心,我尝试更改 scaleType 但没有任何效果。
【问题讨论】:
标签: android android-fragments progress-bar android-progressbar