gpt4 book ai didi

java - 如何禁用布局对齐?

转载 作者:行者123 更新时间:2023-12-01 13:59:12 28 4
gpt4 key购买 nike

我正在尝试将 Eclipse 中的一堆对象与 Android 插件对齐。它们都相互链接,当我更改框中的文本时,这是有问题的。我可以做什么来改变它自动对齐的方式?将所有 android:layout ...=""设置为“false”?这是 xml 文件。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<CheckBox
android:id="@+id/chckBxContd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@+string/RunContd"
android:textSize="15sp"
android:textStyle="bold" />

<TextView
android:id="@+id/lblUke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/chckBxContd"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="@+string/lblUke"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
android:id="@+id/btnCUke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/lblUke"
android:layout_marginLeft="27dp"
android:layout_toRightOf="@+id/lblUke"
android:text="@+string/btnCUke" />

<Button
android:id="@+id/btnGUke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnCUke"
android:layout_alignBottom="@+id/btnCUke"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@+id/lblUke"
android:text="@+string/btnGUke" />

<Button
android:id="@+id/btnEUke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnGUke"
android:layout_below="@+id/btnGUke"
android:layout_marginTop="32dp"
android:text="@+string/btnEUke" />

<Button
android:id="@+id/btnAUke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnEUke"
android:layout_alignBottom="@+id/btnEUke"
android:layout_alignLeft="@+id/btnCUke"
android:text="@+string/btnAUke" />

<TextView
android:id="@+id/lblGuitar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@+string/lblGuitar"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
android:id="@+id/btnDGuitar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnAUke"
android:layout_below="@+id/lblGuitar"
android:layout_marginTop="19dp"
android:text="@+string/btnDGuitar" />

<Button
android:id="@+id/btnAGuitar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnDGuitar"
android:layout_alignBottom="@+id/btnDGuitar"
android:layout_toRightOf="@+id/btnGUke"
android:text="@+string/btnAGuitar" />

<Button
android:id="@+id/btnLowEGuitar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnAGuitar"
android:layout_alignBottom="@+id/btnAGuitar"
android:layout_alignRight="@+id/btnEUke"
android:text="@+string/btnLowEGuitar" />

<Button
android:id="@+id/btnGGuitar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnLowEGuitar"
android:layout_below="@+id/btnLowEGuitar"
android:layout_marginTop="24dp"
android:text="@+string/btnGGuitar" />

<Button
android:id="@+id/btnBGuitar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnGGuitar"
android:layout_alignBottom="@+id/btnGGuitar"
android:layout_centerHorizontal="true"
android:text="@+string/btnBGuitar" />

<Button
android:id="@+id/btnHighEGuitar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/btnBGuitar"
android:layout_alignRight="@+id/btnDGuitar"
android:text="@+string/btnHighEGuitar" />

这就是我希望它看起来的样子,文本是对象...... enter image description here

这是程序的图片,它还有一些按钮显示错误,当他们应该说一个字母时,不确定那是什么。. enter image description here

最佳答案

此问题是当文本更改时布局会调整宽度。

一个可能的解决方案是使用 TableLayoutTableRows 结合使用。 TableLayouts 会将所有内容对齐在一起。当里面的文本发生变化时,行大小将保持不变。

或者您可以对每一行使用LinearLayout。将 weightSum 属性设置为任意数字。将每个 TextView(或 LinearLayout 中的任何直接子级)weight 属性设置为weightSum 的一半。无论文本是什么,LinearLayout 都会使容器保持相同的大小。

事实上,TableLayout 扩展了 LinearLayout,这就是它背后的底层机制。

关于java - 如何禁用布局对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19438897/

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