人麻了,下载之后安卓虚拟机没法关联布局文件

img

img

自己创建的layout,自己创建的Main Activity.,虚拟机也能动,就是运行不了我创建的文件,只有一个默认的Hello Android

img

  • 你可以看下这个问题的回答https://ask.csdn.net/questions/168238
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:Android-如何把Layout和Activity建立起联系
  • 你还可以看下android参考手册中的 android Layout 一个基类,管理屏幕上视觉元素的文本布局。 的基类。
  • 除此之外, 这篇博客: Android-Activity(三)生命周期中的 编写layout文件 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • layout_normal.xml
    添加了一个TextView

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="This is a normal activity" />
    </LinearLayout>
    

    layout_dialog.xml
    添加了一个TextView

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="This is a dialog activity" />
    
    </LinearLayout>
    

    layout_main.xml
    有两个按钮分别用来启动NormalActivity和DialogActivity

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <Button
            android:id="@+id/startNormalActivity"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="Start Normal Activity"
            android:textAllCaps="false"
            />
        <Button
            android:id="@+id/startDialogActivity"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="Start Dialog Activity"
            android:textAllCaps="false"
            />
    
    </LinearLayout>