较低的Android API片段 [英] Android Fragments on lower API
问题描述
以及我开始了解Android的碎片,但是这仍然是困惑我。我需要一点点帮助。因为它说Android的碎片,因为API级别11支持,但你可以下载support.v4库打包较低级别的API。那么首先我创建新的项目,试穿API级别15.然后片段我与API级别8相同,这是行不通的。我引入的外部罐子,它认为所有需要的进口,因为它应该...什么似乎是这里的问题?
well I'm starting to understand Android Fragments but this is still confusing for me. I need a little help. As it says android fragments is supported since API level 11 but you can download "support.v4" libraries pack for lower level APIs. Well first I create new project to try fragments on API level 15. Then I did the same with API level 8 and it does not work... I imported external jar and it sees all needed import as it should... What seems to be the problem here?
下面是我的主类:
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
public class Fragment2Activity extends FragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
我主要布局XML:
My main layout 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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<fragment
android:name="com.frag.Fragment2.frag"
android:id="@+id/frag"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
我的片段类:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class frag extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.hello_fragment, container, false);
return v;
}
}
和我的片段布局XML:
And my fragment layout XML:
<?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="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:text="THIS IS FRAGMENT"
android:background="@drawable/ic_launcher"
/>
</LinearLayout>
固定
推荐答案
您还在使用 android.view.fragment
类,它不存在。你必须切换到 android.support.v4.app.fragment
旧设备上。
You are still using the android.view.fragment
class, which does not exist. You have to switch to android.support.v4.app.fragment
on older devices.
这篇关于较低的Android API片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!