Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 线性布局不对齐基线,相对布局不允许权重大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个垂直方向的线性布局,我在其中插入了几个视图组.其中之一是:

<LinearLayout
   android:id="@+id/addedit_updowncontrol"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layouT_Below="@+id/textView2"
   android:layout_marginBottom="5dp" 
   android:orientation="horizontal">

    <Button
        android:id="@+id/addediT_Btndecrement"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_weight="0.1"
        android:text="-" />

    <EditText
        android:id="@+id/addedit_txtQuantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="90dp"
        android:layout_weight="0.4"
        android:layout_alignParentTop="true"
        android:inputType="numberdecimal" />

    <Button
        android:id="@+id/addediT_BtnIncrement"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_weight="0.1"
        android:layout_toLeftOf="@+id/addedit_units"
        android:text="+" />

    <Spinner
        android:id="@+id/addedit_units"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
            android:layout_weight="0.4"
        android:layout_alignParentTop="true"
    android:layout_alignParentright="true" />

</LinearLayout>

这给了我一个看起来像this的观点(对链接道歉,我希望有更好的方法).这是不可接受的,因为Button没有与EditText对齐.

我尝试切换到RelativeLayout,这给了我像this这样的东西.这是不可接受的,因为两个按钮( – )和()的宽度不同.

我想我想要实现的目标是:
(1)Button的基线与行中的其他控件对齐.
(2)两个按钮宽度相同.

我似乎能够用RelativeLayout和(2)用LinearLayout实现(1)但不是两者都有.

有人可以帮我吗?

解决方法

使用

android:gravity="center_vertical"

你的线性布局中.所有项目都将居中

大佬总结

以上是大佬教程为你收集整理的android – 线性布局不对齐基线,相对布局不允许权重全部内容,希望文章能够帮你解决android – 线性布局不对齐基线,相对布局不允许权重所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。