Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将布局XML获取到CustomView布局_Android_Android Layout_Android Widget_Android Custom View - Fatal编程技术网

Android 将布局XML获取到CustomView布局

Android 将布局XML获取到CustomView布局,android,android-layout,android-widget,android-custom-view,Android,Android Layout,Android Widget,Android Custom View,这是一个非常简单的布局,我希望在上实现。但是,我尝试了许多方法使我的customView显示在按钮的侧面-LinearLayout。但我失败了。任何帮助都将不胜感激 谢谢大家! 这是我在MainActivity中声明CustomView的地方 public class Drawing extends Activity { mContent = (LinearLayout) findViewById(R.id.labelCreator); mSignature = new Res

这是一个非常简单的布局,我希望在上实现。但是,我尝试了许多方法使我的customView显示在按钮的侧面-LinearLayout。但我失败了。任何帮助都将不胜感激
谢谢大家!

这是我在MainActivity中声明CustomView的地方

public class Drawing extends Activity {

   mContent = (LinearLayout) findViewById(R.id.labelCreator);

   mSignature = new Resize(this, null);

   mContent.addView(mSignature);
........... 
我的XML布局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    android:id="@+id/Drawing"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:visibility="visible" >

    <LinearLayout
        android:id="@+id/interface2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:layout_marginTop="0dp"
        android:background="#8b5a2b"
        android:orientation="horizontal" >

                <TableLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >


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

                            <TableLayout
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content" >

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

                                    <Button
                                        android:id="@+id/btnPhoto"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:drawableTop="@drawable/camera2"
                                        android:text="Camera"
                                        android:textColor="#ffffff"
                                        android:textSize="25sp"
                                        android:typeface="serif" />

                                    <Button
                                        android:id="@+id/btnImage"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:drawableTop="@drawable/image"
                                        android:text="Image"
                                        android:textColor="#ffffff"
                                        android:textSize="25sp"
                                        android:typeface="serif" />

                                </TableRow>

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

                                    <Button
                                        android:id="@+id/btnText"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:drawableTop="@drawable/text"
                                        android:text="Text"
                                        android:textColor="#ffffff"
                                        android:textSize="25sp"
                                        android:typeface="serif" />

                                    <EditText
                                        android:id="@+id/editText1"
                                        android:layout_width="180dp"
                                        android:layout_height="wrap_content"
                                        android:ems="10"
                                        android:freezesText="false"
                                        android:hint="text"
                                        android:maxLength="10"
                                        android:maxLines="1"
                                        android:textAlignment="center"
                                        android:textColor="#e6e6fa"
                                        android:textSize="25sp"
                                        android:typeface="serif"
                                        android:visibility="visible" />

                                </TableRow>

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

                                    <Spinner
                                        android:id="@+id/color_spinner"
                                        android:layout_width="135dp"
                                        android:layout_height="wrap_content"
                                        android:textAlignment="center" />

                                    <Spinner
                                        android:id="@+id/fonts_spinner"
                                        android:layout_width="132dp"
                                        android:layout_height="wrap_content"
                                        android:textAlignment="center"
                                        app:context=".LabelCreator" />

                                </TableRow>

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

                                    <Button
                                        android:id="@+id/btnSave"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:drawableTop="@drawable/save3"
                                        android:text="Save"
                                        android:textColor="#ffffff"
                                        android:textSize="25sp"
                                        android:typeface="serif" />

                                    <Button
                                        android:id="@+id/btnClear"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:drawableTop="@drawable/clear"
                                        android:text="Clear"
                                        android:textColor="#ffffff"
                                        android:textSize="25sp"
                                        android:typeface="serif" />

                                </TableRow>
                            </TableLayout>

                        </TableRow>

                        <Button
                            android:id="@+id/btnClose"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:drawableRight="@drawable/close"
                            android:shadowColor="#00000000"
                            android:text="Close"
                            android:textColor="#ffffff"
                            android:textSize="25sp"
                            android:typeface="serif" />

                            <Button
                                android:id="@+id/btnAbout"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="About"
                                android:textColor="#ffffff"
                                android:textSize="25sp"
                                android:typeface="serif" />

                </TableLayout>

    </LinearLayout>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="250dp"
        android:layout_height="85dp"
        android:maxLines="1"
        android:singleLine="true"
        android:text="TextView"
        android:textSize="20sp"
        android:visibility="invisible" />

</LinearLayout>

这只是一个要遵循的结构

<?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="horizontal"
    android:weightSum="10" >

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="3"
        android:orientation="vertical" >

        <Button
            android:id="@+id/btnSave"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/save3"
            android:text="Save"
            android:textColor="#ffffff"
            android:textSize="25sp"
            android:typeface="serif" />

        <Button
            android:id="@+id/btnClear"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/clear"
            android:text="Clear"
            android:textColor="#ffffff"
            android:textSize="25sp"
            android:typeface="serif" />

        <Spinner
            android:id="@+id/color_spinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAlignment="center" />

        <Spinner
            android:id="@+id/fonts_spinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            app:context=".LabelCreator" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="7" >
// your custom view(Drawing area) will be here.
    </LinearLayout>

</LinearLayout>

//您的自定义视图(绘图区域)将显示在此处。
在这里,父布局具有android:orientation=“horizontal”
,因此其所有子布局都将按列显示。
如果您想要按行显示,请使用android:orientation=“vertical”。在这里,我使用垂直布局作为具有
控件的父布局。
您将根据需要对其进行更改。

希望这会有所帮助。

这只是一个需要遵循的结构

<?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="horizontal"
    android:weightSum="10" >

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="3"
        android:orientation="vertical" >

        <Button
            android:id="@+id/btnSave"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/save3"
            android:text="Save"
            android:textColor="#ffffff"
            android:textSize="25sp"
            android:typeface="serif" />

        <Button
            android:id="@+id/btnClear"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/clear"
            android:text="Clear"
            android:textColor="#ffffff"
            android:textSize="25sp"
            android:typeface="serif" />

        <Spinner
            android:id="@+id/color_spinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAlignment="center" />

        <Spinner
            android:id="@+id/fonts_spinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            app:context=".LabelCreator" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="7" >
// your custom view(Drawing area) will be here.
    </LinearLayout>

</LinearLayout>

//您的自定义视图(绘图区域)将显示在此处。
在这里,父布局具有android:orientation=“horizontal”
,因此其所有子布局都将按列显示。
如果您想要按行显示,请使用android:orientation=“vertical”。在这里,我使用垂直布局作为具有
控件的父布局。
您将根据需要对其进行更改。

希望这会有所帮助。

谢谢你的帮助。您要做的是将控件放在顶部?您还可以将“滚动视图”作为所有控件的父控件,以便可以放置尽可能多的控件。但这只是一个建议,您可以根据自己的要求对其进行更改:)谢谢您的帮助。您要做的是将控件放在顶部?您还可以将“滚动视图”作为所有控件的父控件,以便可以放置尽可能多的控件。但这只是一个建议,您可以根据自己的要求对其进行更改:)