android:eclipse中没有显示布局
layout_span不起作用,当我编写android:layout_s并按下ctrl+space以获取可能的建议时,eclipse没有显示任何layout_span选项 忽略这个,我复制并粘贴了它(android:eclipse中没有显示布局,android,eclipse,android-tablelayout,Android,Eclipse,Android Tablelayout,layout_span不起作用,当我编写android:layout_s并按下ctrl+space以获取可能的建议时,eclipse没有显示任何layout_span选项 忽略这个,我复制并粘贴了它(layout\u span=“2”)。但没有给出预期的结果。它将行划分为如下所示 ------------------------------------ | (about)%40 | (about)%60 | -----------------------------------
layout\u span=“2”
)。但没有给出预期的结果。它将行划分为如下所示
------------------------------------
| (about)%40 | (about)%60 |
------------------------------------
| %33 | %33 | %33 |
------------------------------------
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="200dip"
android:layout_marginRight="10dip" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="@+id/textView1"
android:layout_weight="1"
android:gravity="right"
android:text="Column 1"
android:textAppearance="@style/BoldBlue" />
<TextView
android:id="@+id/textView2"
android:layout_weight="1"
android:layout_span="2"
android:text="Column 2"
android:gravity="center"
android:textAppearance="@style/Normal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="@+id/textView4"
android:layout_weight="1"
android:gravity="right"
android:text="Column 1"
android:textAppearance="@style/BoldBlue" />
<TextView
android:id="@+id/textView5"
android:layout_weight="1"
android:text="Column 2"
android:gravity="center"
android:textAppearance="@style/Normal" />
<TextView
android:id="@+id/button2"
android:layout_weight="1"
android:text="Column 3"
android:gravity="center"
android:textAppearance="@style/Normal" />
</TableRow>
</TableLayout>
style.xml
<style name="BoldBlue">
<item name="android:textSize">18sp</item>
<item name="android:textColor">#0000FF</item>
<item name="android:textStyle">bold</item>
<item name="android:gravity">right</item>
</style>
<style name="BoldGreenCenter">
<item name="android:textSize">18sp</item>
<item name="android:textColor">#00FF00</item>
<item name="android:textStyle">bold</item>
<item name="android:gravity">center</item>
</style>
<style name="Normal">
<item name="android:textSize">15sp</item>
<item name="android:gravity">center</item>
</style>
18便士
#0000FF
大胆的
正确的
18便士
#00FF00
大胆的
居中
15便士
居中
尝试将布局span=“1”
添加到第一行的第一列,您可以使用布局权重属性进行添加。请尝试以下内容:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="right"
android:text="Column 1" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="#FF0000"
android:gravity="center"
android:text="Column 2" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#3366FF"
android:gravity="right"
android:text="Column 1" />
<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Column 2" />
<TextView
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Column 3" />
</TableRow>
</TableLayout>
输出:在Eclipse中,XML代码助手不会提示属性“android:layout\u span”、“android:layout\u column”和许多其他有用的TableLayout属性,不知道为什么,可能是bug。只需将该属性放在里面,它仍然可以编译和运行。
我遇到了问题。无法修复请帮助。这太奇怪了。我将第一个textview权重设置为2,第二个textview权重设置为5,然后得到所需的结果。但这将在不同的屏幕大小下运行。保存我发布的您尝试过的布局?我添加了结果的屏幕截图。这不是您想要的吗?谢谢:)是的,您的代码工作正常。谢谢,但wlayout\u span有问题。为什么它不起作用?我一直在表格行上使用layout\u weight attr(因为我知道TableRow是LinearLayout的一个子类)。我想如果你将layout\u span attr的正确值应用于TableLayout下的所有视图(我指的是布局中的所有文本视图)这也行。例如,在第一行1,2和第二行1,1,1尝试设置为所有文本视图的布局跨度值。