android:layout_gravity将使子视图垂直居中,而不是水平居中
布局XML为:android:layout_gravity将使子视图垂直居中,而不是水平居中,android,layout,Android,Layout,布局XML为: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/transl
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/translucenter_dark" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="200dip"
>
<ProgressBar android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
></ProgressBar>
</LinearLayout>
</LinearLayout>
最终的布局是:
为什么progressBar没有垂直和水平放置在中心。这是一个特性还是一个bug:)你可以给出包含进度条的线性布局
android:gravity=“center”
。
这将使进度条居中
进度条似乎利用了。此类不支持布局图,例如。因此,需要使用父线性布局的重力特性。这是android中的一个很好的解释。您可以给出包含进度条的线性布局
android:gravity=“center”
。
这将使进度条居中
进度条似乎利用了。此类不支持布局图,例如。因此,需要使用父线性布局的重力特性。这是一个很好的解释,在安卓系统中。是的。我明白这是可行的。我想理解的是为什么布局重力不起作用。更新+1。但是,用TextView替换ProgressBar,布局也不会水平居中。TextView还利用ViewGroup.LayoutParams。如果父线性布局的方向为垂直,布局\重力将居中水平。我给你的链接是迄今为止我找到的最好的解释。我明白这是可行的。我想理解的是为什么布局重力不起作用。更新+1。但是,用TextView替换ProgressBar,布局也不会水平居中。TextView还利用ViewGroup.LayoutParams。如果父线性布局的方向为垂直,布局\重力将居中水平。我给你的链接是迄今为止我找到的最好的解释。