Android Hello World App "activity_my" file different from described

时间:2015-10-30 21:46:12

标签: java android xml android-studio

I am new to Android development so I decided to start off by following the instructions on the tutorial on http://developer.android.com/training/basics/firstapp/building-ui.html.

After creating a blank activity and running it, the next step is to create a UI. It is implied by the instructions that the activity_my.xml file contains a RelativeLayout root view and a TextView child view. However, upon opening the file this is what I found

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true"
    tools:context=".MyActivity">

    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_my" />

    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

Which is apparently not what should have been produced. I have searched through other questions but haven't found this particular problem anywhere else. Any help or insight would be much appreciated, thanks!

1 个答案:

答案 0 :(得分:0)

The layout your xml file contains depends by what you chose when you create the project in your IDE (Blank Activity, Activity with Fragments, ecc...).

If you want to use the code of the tutorial you can just replace the code generated by your IDE and use the one provided by the tutorial:

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

With this you'll have a simple activity with a LinearLayout.