无法在Android中设置进度条高度
我是Android新手,尝试在视图中心定位所有控件。不幸的是,尽管我设置了无法在Android中设置进度条高度,android,android-layout,Android,Android Layout,我是Android新手,尝试在视图中心定位所有控件。不幸的是,尽管我设置了50dp,但我的进度条显示为零高度: 代码如下 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:cont
50dp
,但我的进度条显示为零高度:
代码如下
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="MYACTIVITY"
android:id="@+id/activity_MY"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:gravity="center">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:id="@+id/progressBar2"
android:layout_above="@+id/button"
android:layout_height="50dp"
android:max="100"
android:progress="50" />
</RelativeLayout>
为什么?
您需要将style=“?android:attr/progressBarStyleHorizontal”
替换为style=“@android:style/Widget.ProgressBar.Horizontal”
及
从父级中移除
layout\u gravity=“center”
,并android:layout\u centerVertical=“true”
以垂直对齐按钮中心
至
style=“@android:style/Widget.ProgressBar.Horizontal”
Hmm。。试着运行你的应用程序有点奇怪,你的进度会有什么结果?为什么会有这样的替换?这些是主题的属性,指向可以用于进度指示器的主题样式。它们的确切值可以随着主题的不同而变化,这只是一个间接层。为什么要这样替换呢?:)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="MYACTIVITY"
android:id="@+id/activity_MY"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:id="@+id/button"/>
<ProgressBar
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:id="@+id/progressBar2"
android:layout_above="@+id/button"
android:layout_height="50dp"
android:max="100"
android:progress="50" />
</RelativeLayout>