Android上的选项卡视图中未显示任何内容
我以以下方式创建tabBar:Android上的选项卡视图中未显示任何内容,android,fragment,android-tabhost,tabview,Android,Fragment,Android Tabhost,Tabview,我以以下方式创建tabBar: import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTabHost; public class FragmentTabs extends FragmentActivity { private FragmentTabHost mTabHost; @Override protected void
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
public class FragmentTabs extends FragmentActivity {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabbar_layout);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("About Us").setIndicator("About Us"), FragmentAboutUsScreen.class, null);
mTabHost.addTab(mTabHost.newTabSpec("Feedback").setIndicator("Feedback"), FragmentFeedbackScreen.class, null);
}
}
FragmentFeedbackScreen.java如下所示:
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class FragmentFeedbackScreen extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO Auto-generated method stub
//return super.onCreateView(inflater, container, savedInstanceState);
Log.e("Fragment:", "VIEW");
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_feedback_screen, container, false);
}
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.e("Fragment:", "here");
}
}
fragment_feedback_screen.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:background="@color/background">
<TextView
android:id="@+id/rateTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="@string/rateUs" />
<RatingBar
android:id="@+id/rattings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/rateTextView"
android:layout_below="@+id/rateTextView"
android:layout_marginTop="20dp" />
<EditText
android:id="@+id/emailId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/rattings"
android:layout_below="@+id/rattings"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="@string/emailId"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/emailId"
android:layout_below="@+id/emailId"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="@string/write_your_message"
android:inputType="textMultiLine" >
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/message"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/message"
android:layout_marginBottom="20dp"
android:text="@string/sendMessage" />
</RelativeLayout>
但当我点击“反馈”选项卡时,该视图中并没有显示任何内容。
这有什么问题
编辑(LOGCAT日志):
01-20 16:28:29.452: I/Adreno200-EGL(19888): <qeglDrvAPI_eglInitialize:290>: EGL 1.4 QUALCOMM build: (Merge)
01-20 16:28:29.452: I/Adreno200-EGL(19888): Build Date: 09/29/12 Sat
01-20 16:28:29.452: I/Adreno200-EGL(19888): Local Branch:
01-20 16:28:29.452: I/Adreno200-EGL(19888): Remote Branch:
01-20 16:28:29.452: I/Adreno200-EGL(19888): Local Patches:
01-20 16:28:29.452: I/Adreno200-EGL(19888): Reconstruct Branch:
01-20 16:28:45.772: E/Fragment:(19888): here1
01-20 16:28:45.772: E/Fragment:(19888): here
01-20 16:28:47.202: E/Fragment:(19888): here1
01-20 16:28:47.202: E/Fragment:(19888): here
01-20 16:28:48.092: E/Fragment:(19888): here1
01-20 16:28:48.092: E/Fragment:(19888): here
01-20 16:28:29.452:I/Adreno200 EGL(19888)::EGL 1.4高通公司构建:(合并)
01-20 16:28:29.452:I/Adreno200 EGL(19888):建造日期:2012年9月29日星期六
01-20 16:28:29.452:I/Adreno200 EGL(19888):当地分行:
01-20 16:28:29.452:I/Adreno200 EGL(19888):远程分支:
01-20 16:28:29.452:I/Adreno200 EGL(19888):局部斑块:
01-20 16:28:29.452:I/Adreno200 EGL(19888):重建分支:
01-20 16:28:45.772:E/片段:(19888):此处1
01-20 16:28:45.772:E/片段:(19888):这里
01-20 16:28:47.202:E/片段:(19888):此处1
01-20 16:28:47.202:E/片段:(19888):这里
01-20 16:28:48.092:E/片段:(19888):此处1
01-20 16:28:48.092:E/片段:(19888):这里
EDIT-2(tabbar\u layout.xml)
好,问题出在tabbar_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" >
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
您的代码似乎是正确的,与android开发人员的示例非常相似。。。你能看一下日志猫并回复你的日志打印了哪些行吗?事实上,我没有收到任何错误,尽管我已经添加了日志。有人能告诉我我的错误或任何其他解决方案吗?拜托,我被困在这里了(在我的发布暂停期间没有问题,我可以抽出几分钟切换到我的android env并尝试这个非常奇怪的问题;)我很抱歉,我已经完全尝试了你的代码,它工作得很好。我亲手编写的唯一代码是tabbar_layout.xml。您可以编辑您的回复并编写此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" >
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>