Kęs*_*kas 4 api android android-fragments
好吧,我开始了解Android碎片,但这对我来说仍然很困惑.我需要一些帮助.因为它说自API级别11以来支持android片段,但您可以下载"support.v4"库包以获得更低级别的API.首先,我创建新的项目来尝试API级别15的片段.然后我做了同样的API级别8,它不起作用...我导入外部jar,它看到所有需要导入,因为它应该...似乎这是问题吗?
这是我的主要课程:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我的主要布局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>
Run Code Online (Sandbox Code Playgroud)
我的片段类:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我的片段布局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>
Run Code Online (Sandbox Code Playgroud)
固定
| 归档时间: |
|
| 查看次数: |
7754 次 |
| 最近记录: |