2014-10-01 128 views
0

我遇到了一些动态生成的按钮问题。如果文字太多,他们会离开屏幕。你可以看到它的图片:Android - 动态按钮关闭屏幕

enter image description here

如果在按钮上的文本是小那么问题不出来,但如果字符数是高的,那么按钮上显示出来的画面。

按钮的布局如下:

<?xml version="1.0" encoding="UTF-8"?> 
<Button xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/newGuessButton" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_weight="1" 
android:layout_alignParentRight="true" > 
</Button> 

和按钮在表中的布局创建:

<TableLayout android:id="@+id/buttonTableLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" android:stretchColumns="0,1,2"> 
    <TableRow android:id="@+id/tableRow0" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"></TableRow> 
    <TableRow android:id="@+id/tableRow1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"></TableRow> 
    <TableRow android:id="@+id/tableRow2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"></TableRow> 

重要的是要注意,这桌走了进去是很重要的线性布局。

是否有反正我可以将按钮的大小限制为使用它们的屏幕大小?

+0

你必须使用一个表吗?怎么样一个gridview? – AndroidEnthusiast 2014-10-02 10:14:55

+0

我不必使用表格。使用gridview更好吗?它如何帮助解决这个问题? – 2014-10-02 16:45:56

回答

1

我会建议使用一个GridView,而不是tablelayout:

使用一个GridView会好很多,因为:

  • 您可以设置列数
  • 的全部宽度列将是相同的
  • 如果文本不能放在textview中,那么它将转到下一行,而不是在
    视图之外。

下面是一个使用GridView的一些详细信息 - http://developer.android.com/guide/topics/ui/layout/gridview.html

+0

太棒了,我会用gridView来试试。 – 2014-10-02 16:52:26