0

我试图将 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" />

这就是我希望它看起来的样子,文本是对象...... 在此处输入图像描述

这是程序外观的图片,它还有一些按钮说假,当他们应该说一个字母时,不知道那是关于什么的..在此处输入图像描述

4

1 回答 1

1

这个问题是当文本更改时布局正在调整宽度。

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

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

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

于 2013-10-18T00:49:28.887 回答