gpt4 book ai didi

android:layout_gravity 会将 subview 垂直而不是水平放置在中心

转载 作者:行者123 更新时间:2023-11-29 14:55:41 30 4
gpt4 key购买 nike

布局 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/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>

最终的布局是:

enter image description here

为什么 progressBar 没有在垂直和水平方向上都居中。它是功能还是错误:)

最佳答案

您可以给出包含进度条的线性布局 android:gravity="center"。这将使进度条居中。

进度条似乎利用了 ViewGroup.LayoutParams .此类不支持 layout_gravity 如 LinearLayout.LayoutParams .所以你需要使用父线性布局的 gravity 属性。这是对 gravity 的一个很好的解释在安卓中。

关于android:layout_gravity 会将 subview 垂直而不是水平放置在中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7328579/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com