2010-12-01 219 views
1

我刚刚开始Android,并已陷入困境。我做了一个简单的应用程序/视图。这个想法是在顶部画线迷宫,底部有动作按钮。我的应用程序只在框架中绘制了一对x,但有效。问题在于我的按钮被拉得太低,并且高度被限制。嵌套布局的问题

我认为问题都在我的布局XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

     <FrameLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" > 

      <none.maze.MazeView 
      android:id="@+id/maze" 
       android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         /> 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" > 
       <TextView 
       android:id="@+id/text" 
        android:text="@string/maze_layout_text_text" 
        android:visibility="visible" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:gravity="center_horizontal" 
        android:textColor="#ff8888ff" 
        android:textSize="24sp"/> 
      </RelativeLayout> 

     </FrameLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" >    

      <Button 
       android:id="@+id/left" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Left" 
       android:layout_weight="1" 
       /> 

      <Button 
       android:id="@+id/forward" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Forward" 
       android:layout_weight="1" 
       /> 

      <Button 
       android:id="@+id/right" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Right" 
       android:layout_weight="1" 
       /> 

     </LinearLayout> 

</LinearLayout> 

回答

1

我认为你不应该同时使用layout_height="fill_parent"layout_weight。尝试为FrameLayoutlayout_height="wrap_content"设置layout_height="0dip"layout_weight="1",对于较低的LinearLayout。较低的LinearLayout不得具有layout_weight属性。

+0

谢谢精灵,这对我很有用。 – 2010-12-01 19:53:11

0

使用Hierarchy Viewer调试布局。它太酷了。

+0

这很酷,我会记住它。这次事情是在正确的地方,所以他们在观众中看起来是正确的。 – 2010-12-01 19:54:11

+9

请注意层次结构查看器不适用于生产版本(操作系统,而不是您的应用程序)。它会失败,出现“hierarchyviewer:无法调试设备”消息。如果您的手机上没有调试版本,则可以在仿真设备上使用它。 – 2010-12-19 17:02:38

0

您的整个布局只是太臃肿和无效。您使用方式太多ViewGroup s。我建议阅读关于RelativeLayout s,尤其是整个Layout Tricks系列。