2012-03-12 141 views
0

我正在尝试Finger Paint API演示,并试图向其添加按钮。我已包含使用视图添加按钮布局

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

    <view 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.triopsys.imosandroid.ViewControllers.SignatureViewController$MyView" /> 

</LinearLayout> 

在我的布局xml中,但我无法在此视图的顶部或底部添加按钮;

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

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/buttonCancel" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Cancel" > 
     </Button> 

     <Button 
      android:id="@+id/buttonOk" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="OK" > 
     </Button> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <view 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      class="com.triopsys.imosandroid.ViewControllers.SignatureViewController$MyView" /> 
    </LinearLayout> 

</LinearLayout> 

但这不起作用。

+1

您是否收到某种错误? – iTurki 2012-03-12 13:59:59

回答

0

尝试增加

android:orientation="horizontal" 

的布局包裹你的按钮。 IIRC的默认设置是垂直的,所以它将2个宽度为零的按钮叠加在一起。

+0

默认方向是[horizo​​ntal](http://d.android.com/reference/android/widget/LinearLayout.html)。 – 2012-03-12 14:10:35

+0

就这样。我很抱歉。一旦我确认了以下内容,我会修复该帖子:我不在我的开发机器中,但似乎也存在OPs“View”大小的问题,该大小设置为“match_parent”,然后是“LinearLayout”它位于'wrap_content'中,因此需要多大的高度?全屏? – CjS 2012-03-12 14:19:40

0

如果您收到任何错误:

话,我想这个问题是与按钮的宽度值。将其更改为wrap_content

0

究竟是什么不起作用?我试过这种布局,它编译并正确显示。

如果“不起作用”的意思是“我的自定义视图不占用整个屏幕”,则删除linearLayout2。无论如何,这是多余的,可能会被删除。

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

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/buttonCancel" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Cancel" > 
     </Button> 

     <Button 
      android:id="@+id/buttonOk" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="OK" > 
     </Button> 
    </LinearLayout> 

    <view 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.triopsys.imosandroid.ViewControllers.SignatureViewController$MyView" /> 

</LinearLayout>