Fra*_*ita 3 layout android android-intent
我有这个布局文件的主要活动:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
android:id="@+id/container"
>
<LinearLayout
android:layout_height="wrap_content"
android:id="@+id/header"
android:background="@drawable/logo_bk"
android:layout_width="fill_parent"
>
<Button
android:id="@+id/btn_reload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reload"
/>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal"
>
<ImageView
android:id="@+id/ImageView01"
android:src="@drawable/logo_head"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/center"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1">
</FrameLayout>
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center"
android:id="@+id/footer"
android:layout_weight="2.6"
android:background="#ffffff">
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
基本上它由一个标题,一个中心部分(android:id ="@ + id/center")和一个页脚组成.页脚包含四个动态创建的按钮.最后,它看起来像一个TabWidget,底部有标签.
每个页脚的按钮都包含一个意图/活动.
问题是:如何将我的活动开始进入FrameLayout?比如TabHost这样做:
spec = tabHost
.newTabSpec(tabTitle.toLowerCase())
.setIndicator(tabTitle,res.getDrawable(R.drawable.tab_spec))
.setContent(intent);
tabHost.addTab(spec);
Run Code Online (Sandbox Code Playgroud)
如果要为要显示的每个页面分别设置活动,则必须为容器活动(显示选项卡的活动)扩展ActivityGroup,并使用LocalActivityManager来管理要使用的不同嵌入式活动.
它有点复杂,没有记录.我必须阅读TabHost的源代码.
搜索class IntentContentStrategy.
基本上,这个想法是,你有一个容器视图,并使用LocalActivityManager加载活动,得到它的视图,并将其放置在容器视图中.
TabHost.java的摘录:
public View getContentView() {
if (mLocalActivityManager == null) {
throw new IllegalStateException("Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?");
}
final Window w = mLocalActivityManager.startActivity(
mTag, mIntent);
final View wd = w != null ? w.getDecorView() : null;
if (mLaunchedView != wd && mLaunchedView != null) {
if (mLaunchedView.getParent() != null) {
mTabContent.removeView(mLaunchedView);
}
}
mLaunchedView = wd;
// XXX Set FOCUS_AFTER_DESCENDANTS on embedded activities for now so they can get
// focus if none of their children have it. They need focus to be able to
// display menu items.
//
// Replace this with something better when Bug 628886 is fixed...
//
if (mLaunchedView != null) {
mLaunchedView.setVisibility(View.VISIBLE);
mLaunchedView.setFocusableInTouchMode(true);
((ViewGroup) mLaunchedView).setDescendantFocusability(
FOCUS_AFTER_DESCENDANTS);
}
return mLaunchedView;
}
Run Code Online (Sandbox Code Playgroud)
注意:你需要做很多调整和奇怪的事情来使这些东西工作(注意它们在评论中引用的bug),这可能就是为什么它没有记录.
| 归档时间: |
|
| 查看次数: |
7937 次 |
| 最近记录: |