【问题标题】:Unknown space on top of ProgressBarProgressBar 顶部的未知空间
【发布时间】:2017-10-18 15:18:10
【问题描述】:

所以我想在下面link(material.io)

中实现与材料指南中相同的风格

到目前为止,我已经尝试过这种方式:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

<ProgressBar
    android:indeterminate="true"
    android:id="@+id/progressbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/Widget.AppCompat.ProgressBar.Horizontal"
    />

<LinearLayout
    android:elevation="2dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:background="@color/white"
    android:orientation="vertical"
    android:paddingBottom="64dp"
    android:paddingLeft="64dp"
    android:paddingRight="64dp"
    android:paddingTop="32dp">

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingBottom="32dp"
        android:paddingTop="32dp"
        android:text="@string/patient_register"
        android:textSize="30sp" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:text="@string/login_with_your_clinic"
        android:textSize="18sp" />

    <EditText
        android:id="@+id/editText5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:ems="10"
        android:hint="@string/email_address"
        android:inputType="textEmailAddress" />

    <EditText
        android:id="@+id/editText6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/password"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/login_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:text="@string/login"
        android:textColor="@color/white"
        android:theme="@style/MyButton" />
</LinearLayout>

结果如下:

为什么动作条和进度条之间有那么大的差距?我怎样才能达到谷歌材料指南中看到的结果?

【问题讨论】:

  • 可以在progressBar中添加marginBottom。
  • @FatihOzcan 为什么要添加底部边距?我想消除 ProgressBar 顶部的间隙
  • 那是因为那个间隙仍然是 ActionBar(它有一些高度)。如果您制作一个没有任何高度的自定义工具栏,则 ActionBar 和 Progressbar 之间不会有任何阴影。
  • 我以为您正在努力弥补这一差距。您可以通过将进度条更改为不同的颜色来检查进度条的宽度和高度,以确保进度条是否均匀放置。可能就像 JMedinilla 所说的那样。当您希望查看视图的宽度和高度时,更改它的颜色是一种简单而有用的解决方案
  • 好吧,我错了,但不是在问题上,而是在组件上。该空间来自进度条。您可以将鼠标放在预览布局上查看组件占用了多少空间,就像 Faith Ozcan 所说:imgur.com/a/jgK5o

标签: android material-design android-progressbar


【解决方案1】:

[编辑 2018-09-20]:不要遵循这种方法。这是不正确的做法,因此不应使用。


ProgressBar 组件添加一个negative ma​​rginTop,使其上升,紧邻ActionBar。

<ProgressBar
    android:id="@+id/progressbar"
    style="@style/Widget.AppCompat.ProgressBar.Horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="-8dp"
    android:indeterminate="true" />

【讨论】:

  • 这不是正确的方法,因为它在不同的设备上会有不同的用户界面。
  • 我知道。这个答案已经快一年了。它不再代表我或我的 Android 能力。
【解决方案2】:

删除进度条顶部空白的最佳解决方案

 <ProgressBar
    android:id="@+id/webProgressbar"
    android:layout_width="match_parent"
    android:layout_height="4dp"
    android:layout_centerHorizontal="true"
    style="@style/Widget.AppCompat.ProgressBar.Horizontal"
    app:layout_constraintTop_toTopOf="parent" 
/>

【讨论】:

    猜你喜欢
    • 2010-12-31
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多