您的位置:首页 > 大数据 > 人工智能

layout文件夹中activity_main.xml与fragment_main.xml文件的处理记录

2017-03-14 20:25 302 查看
androidSDK更新到22.6后新建立项目时在layout文件夹下面出现了activity_main.xml与fragment_main.xml,这是为了在平板开发中使用碎片,但是让不需要碎片的人不习惯,自己做了如下更改

(1)将activity_main.xml中内容替换为fragment_main.xml中内容,删除fragment_main.xml,activity_main.xml内容如下

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.exmple.TwoActivity$PlaceholderFragment" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

</RelativeLayout>


(2)将MainActivity中继承MainActivity extends Activity,删去除第一个外的@override函数,此时会报错重新导入包就可(ctrl+shift+o)修改后的文件如下

package com.example.exmple;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}


这样就可以按照以前的习惯进行开发了,其中导入项目出现invalid project description,查了一下说是文件放到了Android项目文件夹的默认路径下了,会产生相同的文件啥的,只要将该项目换到别的文件夹下面即可。

另外:不要再layout文件上直接新建Android xml文件,直接建xml文件,控制台会报错

[2017-03-14 20:17:05 - Exmple] 'default' is not a best match for any device/locale combination.
[2017-03-14 20:17:05 - Exmple] Displaying it with ', , Locale Language ___Region __, Left To Right, sw320dp, w320dp, h533dp,
Normal Screen, Long screen aspect ratio, Portrait Orientation, Normal, Day time, High Density, Finger-based touchscreen,
Soft keyboard, No keyboard, Exposed navigation, Trackball navigation, Screen resolution 800x480, API Level 19' which is compatible,
but will actually be displayed with another more specific version of the layout.

解决办法:

在工程上右键新建 Android Activity,这时候项目中会自动生成对应的activity.java文件、fragment.xml文件、activity.xml文件,这时候再按照上面的(1)(2)步骤删掉fragment.xml即可。这时候控制台不会再有该报错。

转载:http://blog.csdn.net/xsf50717/article/details/45072069  稍加修改
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐