如何使用Kotlin在Fragment中显示自定义进度条

时间:2018-06-02 18:57:02

标签: android android-fragments android-activity kotlin

我希望能够使用像here这样的自定义进度条。它是一个显示在片段中的计时器,因为我有一个可滑动的布局。我在Android编程方面不是很有经验,我觉得完全迷失了。

任何帮助都会非常感激

FirstFragment.kt

class FirstFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                          savedInstanceState: Bundle?): View? {
    val rootView = inflater.inflate(R.layout.fragment_first, container, false)

    return rootView
}


companion object {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    private val ARG_SECTION_NUMBER = "section_number"

    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    fun newInstance(sectionNumber: Int): FirstFragment {
        val fragment = FirstFragment()
        val args = Bundle()
        args.putInt(ARG_SECTION_NUMBER, sectionNumber)
        fragment.arguments = args
        return fragment
    }
}

}

在第一个片段的xml中,我添加了对象

<ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="350dp"
        android:layout_height="350dp"
        android:layout_centerInParent="true"
        android:indeterminate="false"
        android:max="100"
        android:progress="0"
        android:progressDrawable="@drawable/custom_progressbar_drawable"
        android:secondaryProgress="0" />

0 个答案:

没有答案