无法将表单小部件添加到main.xml文件的图形布局

3D-*_*tiv 3 android

我是Android的新手,我想知道为什么我不能将按钮拖放到main.xml图形布局中的显示器上?看起来它已被锁定或其他我无法弄清楚自己的东西.帮助是精确的!谢谢!

编辑:这是我在xml文件中的代码

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/textview"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:text="@string/hello"
 />
Run Code Online (Sandbox Code Playgroud)

Gho*_*ost 6

您无法这样做,因为您的XML中没有布局.这里给出了一个关于如何构建基本布局的示例.您还可以参考相对布局教程线性布局教程以获取更多详细信息,因为这些是广泛使用的布局.

下面给出了XML的示例代码:

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

    <TextView
        android:id="@+id/textview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

您可以替换Linear LayoutRelative Layout在您方便的.但请记住,如果没有布局,则无法使用图形布局.要拖放布局,请参阅下图:

在此输入图像描述

希望这可以帮助.