2014-10-01 201 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