![](/img/trans.png)
[英]android Surface View with XML Layout and add buttons to a Canvas
[英]Add buttons to layout with a View
我正在嘗試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>
但這是行不通的。
嘗試添加
android:orientation="horizontal"
到包裝您的按鈕的布局。 IIRC的默認值為垂直,因此它將2個寬度為零的按鈕堆疊在一起。
如果沒有錯誤:
那么我想問題出在按鈕的寬度值上。 將其更改為wrap_content
到底什么不起作用? 我嘗試了這種布局,它可以編譯並正確顯示。
如果“不起作用”表示“我的自定義視圖未占據整個屏幕”,則刪除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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.