2015-07-12 153 views
0

我有一个线性布局里面的桌面布局 充气后表中的3个按钮最后一个按钮离开屏幕 我的意思是3个按钮不适合屏幕宽度 我该怎么办?Android:按钮离开屏幕边缘

这里是代码

<TableLayout 
    android:id="@+id/buttonTableLayout" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:stretchColumns="0,1,2" 
    android:layout_weight="1"> 

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

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

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

</TableLayout> 

回答

0

的的TableRow不检查它的内容适合屏幕尺寸。我猜你的按钮占用了所有的空间,因此最后一个按钮在屏幕之外。

我能想到的解决方案2中针对此问题:

  • 使用的LinearLayout与权重为每个按钮:

    <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:orientation="horizontal"> 
    
         <Button 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_margin="8dp" 
          android:layout_weight="1.0" /> 
    
         <Button 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_margin="8dp" 
          android:layout_weight="1.0" /> 
    
    </LinearLayout> 
    

    可以过,当然这是通过编程。 更多关于重量的信息可以在这里找到:https://developer.android.com/guide/topics/ui/layout/linear.html

  • 使用流程布局。它会自动检查您的视图是否适合当前行,并在没有足够空间时将它们放入下一个视图。一个很好的开源库我用我自己是这样的一个:https://github.com/ApmeM/android-flowlayout

+0

的认为这是我使用布局充气服务,就像你说的 我不能添加按钮和按键的文字是不同势(长度)每次我启动应用程序(我从字符串数组中挑选一些随机文本) - 就像一个测验 – Nima

+0

正如我所说,你也可以通过编程来实现。看到这个问题:http://stackoverflow.com/questions/3224193/set-the-layout-weight-of-a-textview-programmatically – rubengees