【问题标题】:ProgressBar and progressBarStyleHorizontal padding [duplicate]ProgressBar 和 progressBarStyleHorizo​​ntal 填充[重复]
【发布时间】:2015-07-18 21:24:52
【问题描述】:

感谢这段代码,我定义了一个进度条:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ProgressBar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?android:attr/progressBarStyleHorizontal"
        android:indeterminate="true"
        android:paddingTop="0dp"
        android:paddingBottom="0dp"
        android:id="@+id/fragment_article_progressBar"
        android:visibility="visible"
        />

        <WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/fragment_article_content"/>

</LinearLayout>

但是当我运行它时,在ProgressBar 的上方和下方添加了一些填充

这似乎不太自然。

是水平ProgressBar的正常样式吗?如果没有,我该如何解决?

干杯

【问题讨论】:

    标签: android layout progress-bar padding


    【解决方案1】:

    尝试如下:

     <ProgressBar
            android:id="@+id/fragment_article_progressBar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-6dp"
            android:layout_marginBottom="-6dp"
            android:indeterminate="true"
            android:max="100"
            android:progress="50"
            android:visibility="visible" />
    

    【讨论】:

    • 谢谢,您的解决方案与 Krupa Patel 的解决方案相同。如果这个解决方案兼容任何屏幕尺寸?
    • 是的,它将与任何屏幕尺寸兼容。
    • 这并不兼容所有设备。
    • 无法在某些 api 上工作
    【解决方案2】:

    尝试替换

     <ProgressBar
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="?android:attr/progressBarStyleHorizontal"
            android:indeterminate="true"
            android:paddingTop="0dp"
            android:paddingBottom="0dp"
            android:id="@+id/fragment_article_progressBar"
            android:visibility="visible"
            />
    

    通过

     <ProgressBar
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="?android:attr/progressBarStyleHorizontal"
            android:indeterminate="true"
            android:layout_marginBottom="-4dp"
            android:layout_marginTop="-4dp"
            android:id="@+id/fragment_article_progressBar"
            android:visibility="visible"
            />
    

    【讨论】:

    • 这个修复似乎有点……脏!它适用于任何设备吗? :-)
    • 如果你不想使用 android:layout_marginBottom="-4dp ,android:layout_marginTop="-4dp" 那么尝试使用android:minHeight="20dip" android:maxHeight="20dip"
    • 谢谢,不幸的是第二种解决方案不起作用(空白空间更大)
    • 只是随机高度。您需要根据需要设置该属性。您可以使用 10 或 12 dp
    • 干杯伙伴,我会接受你的回答!
    猜你喜欢
    • 1970-01-01
    • 2011-01-05
    • 2021-05-11
    • 2021-05-23
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多