2014-03-01 98 views
0

我有一个(可能)平庸但恼人的问题。我有TableRow。在行中有9个按钮,但只有5个可见。如果我缩短了代码,它看起来就像这样:在TableRow中设置按钮大小

XML:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:gravity="fill_vertical"> 

<TableRow 
android:id="@+id/row"/> 

</TableLayout> 

JAVA:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_pokusy); 
    TableRow row = (TableRow)findViewById(R.id.row); 
    for(int i = 0; i < 9; i++){ 
     Button b = new Button(this); 
     row.addView(b); 
    } 
}} 

我已经尝试过什么我发现在互联网上(例如像。 setWidth,setLayoutParams,android:layout_width="..."),但仍然只有9个按钮中的5个在屏幕上可见。 有人可以帮我吗?

+0

您可以发布整个XML吗? – AndyFaizan

+0

你知道...我有一个很长的xml和长的java代码。其实我有9个TableRows,每个都有9个按钮。但是,正如我已经写过的......只有5个是可见的(每行),所以我对自己说,我会尝试做一个实验,并且我创建了一个新的“实验”类,其中xml代码看起来完全像上面的代码。 –

+0

我刚刚测试了你的代码,它似乎在第一行绘制了9个按钮。它正在做你正在告诉它做的这个代码 – AndyFaizan

回答

0

修改你的XML有点让它工作。 shrinkColumns属性使该列适合所需的TableLayout参数。 '*'将其应用于所有列。

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="fill_vertical" 
    android:shrinkColumns="*" > <!-- this makes the difference --> 

    <TableRow 
     android:id="@+id/row" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</TableLayout> 
+0

仍然无效。我真的不知道为什么。还有5个是可见的,而第6个只是部分可见。我想向您发送我可以看到的打印屏幕,但我不知道如何。 –

+0

您是否将TableRow布局参数添加到XML? – AndyFaizan

+0

是的,我做了,但它不起作用 –