Android - 屏幕上的动态按钮

时间:2014-10-01 20:22:40

标签: android xml android-layout

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

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>

重要的是要注意这个表格在线性布局内。

无论如何,我可以将按钮的大小限制为使用它们的屏幕尺寸吗?

1 个答案:

答案 0 :(得分:1)

我建议使用GridView而不是tablelayout:

使用GridView会更好,因为:

  • 您可以设置列数
  • 所有列的宽度都相同
  • 如果文字不适合文本视图,那么它将转到下一行而不是在外面  图。

以下是有关使用GridViews的更多信息 - http://developer.android.com/guide/topics/ui/layout/gridview.html

相关问题