我有两列TableLayout作为滚动视图的唯一子项.第一列包含TextViews("标签")和第二列包含EditText/ Spinner/ DateWidget等("值").尽管我已经指定android:layout_width="fill_parent"了TableLayout,TableRow和所有小工具(在"价值"列).
创建活动时,屏幕看起来很完美.但是,当人们输入一个非常长的值时EditText,"值"列超出了可见的屏幕区域.
我该如何解决这个问题?
我正在与Android糟糕的布局系统作斗争.我正试图让桌子填满屏幕(简单吧?)但是这太难了.
我让它以某种方式在XML中工作,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent">
<TableRow android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1">
<Button android:text="A" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/>
<Button android:text="B" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/>
</TableRow>
<TableRow android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1">
<Button android:text="C" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/>
<Button android:text="D" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/>
</TableRow>
Run Code Online (Sandbox Code Playgroud)
但是我不能让它在Java中工作.我已经尝试过一百万种LayoutParams组合,但没有任何效果.这是我最好的结果,它只填充屏幕的宽度,而不是高度:
table = new TableLayout(this);
// Java. You suck.
TableLayout.LayoutParams lp = new TableLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
table.setLayoutParams(lp); // This line has no effect! WHYYYY?!
table.setStretchAllColumns(true);
for (int r = 0; r < 2; ++r)
{
TableRow row = new TableRow(this);
for …Run Code Online (Sandbox Code Playgroud) 我一直在寻找如何在TableLayout中获取所有TableRow的时间.我已经知道如何动态添加和删除行,但我需要遍历所有行并有选择地删除其中的一些行.
我想我可以提出一个解决方案,但我正试图避免在我的应用程序中粗暴的黑客攻击.
是否可以使表格行展开并折叠?任何人都可以将我推荐给脚本或示例吗?如果可能的话,我更喜欢jQuery.我有一个想要实现的绘图概念:

我正在尝试以编程方式创建TableLayout.它不会起作用.然而,xml文件中的相同布局有效.这就是我所拥有的:
public class MyTable extends TableLayout
{
public MyTable(Context context) {
super(context);
setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
TableRow row = new TableRow(context);
row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
Button b = new Button(getContext());
b.setText("hello");
b.setLayoutParams(new LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
row.addView(b);
addView(row)
}
}
...
// In main activity:
MyTable table = new MyTable(this);
mainLayout.addView(table);
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我没有崩溃,但没有出现.如果我摆脱TableRow实例,至少该按钮确实显示为TableLayout的直接子项.我究竟做错了什么?
when the text cell is large尽管有文字包装,但我无法让我的TableLayout适合屏幕内部inside the cell.
这是我的TableLayout.一个简单的两行,两列表.左列细胞是multiline.如果其中一个单元格的文本很大,则需要在两行中断,该列将被拉伸以填满整个屏幕,并且右列被推出屏幕.
为什么?如何强制全桌留在屏幕内?任何提示都受到欢迎.
我的TableLayout如下:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow>
<TextView
android:text="Account 4 with a very large name to see if it breaks on two or more lines"
android:singleLine="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</TextView>
<TextView
android:text="$400.00"
android:gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</TextView>
</TableRow>
<TableRow>
<TextView
android:text="Account 5"
android:singleLine="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</TextView>
<TextView
android:text="$400.00"
android:gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</TextView>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
显示布局的代码是基本的:
public class AccountBrowserTest
extends Activity
{
public …Run Code Online (Sandbox Code Playgroud) 有没有人知道如何android:layout_span=""在运行时设置/更改Android中的EditText.我已经在我的XML文件中定义了EditText.
<TableRow android:paddingTop="20dip" android:gravity="center_horizontal">
<EditText android:layout_width="150dip"
android:text=""
android:layout_height="40dip"
android:id="@+id/p"
android:layout_span="2">
</EditText>
</TableRow>
Run Code Online (Sandbox Code Playgroud)
我有一个表,每行有2行,有3个按钮.如何使按钮平均填充空间.在HTML中我会给它们33%的宽度.
另外你知道我可以创建一个连续4个图像按钮作为网格布局的视图,类似于启动器.
我想构建以下布局,但它无法正常工作.
alt text http://toms-toy.de/rowspan.gif
<LinearLayout android:orientation="horizontal"...>
<ImageView ...></ImageView>
<TableLayout ...>
<TableRow..>
<ImageView ...></ImageView>
<ImageView ...></ImageView>
<ImageView ...></ImageView>
</TableRow>
<TableRow..>
<ImageView ...></ImageView>
<ImageView ...></ImageView>
<ImageView ...></ImageView>
</TableRow>
</TableLayout>
<ImageView ...></ImageView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) tablelayout ×10
android ×9
layout ×2
tablerow ×2
xml ×2
html-table ×1
java ×1
jquery ×1
layoutparams ×1
views ×1
width ×1