当应用程序从后台返回时,为什么选项卡栏会向下移动几个像素?
代码如下:
public class MenuTabActivity extends TabActivity Implements OnTabChangeListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_layout);
TabHost tb = getTabHost();
TabHost.TabSpec spec = null;
Intent intent = null;
// My Profile tab
intent = new Intent(this, MyProfileActivityGroup.class);
View myProfileView = LayoutInflater.from(this).inflate(R.layout.button_profil, null);
spec = tb.newTabSpec("0").setIndicator(myProfileView).setContent(intent);
tb.addTab(spec);
// Driving tab
intent = new Intent(this, DrivingActivityGroup.class);
View drivingView = LayoutInflater.from(this).inflate(R.layout.button_conduite, null);
spec = tb.newTabSpec("1").setIndicator(drivingView).setContent(intent);
tb.addTab(spec);
// Score Tab
intent = new Intent(this, ScoreActivityGroup.class);
View scoreView = LayoutInflater.from(this).inflate(R.layout.button_score, null);
spec = tb.newTabSpec("2").setIndicator(scoreView).setContent(intent);
tb.addTab(spec);
// Advices Tab
intent = new Intent(this, AdvicesActivity.class);
View advicesView = LayoutInflater.from(this).inflate(R.layout.button_conseils, null);
spec = tb.newTabSpec("3").setIndicator(advicesView).setContent(intent);
tb.addTab(spec);
tb.setOnTabChangedListener(this);
Main.tabBar = tb;
tb.setCurrentTab(0);
}
@Override
public void onTabChanged(String tabId) {
if (tabId.equals("2")){
//refresh third tab
((ScoreActivityGroup)(getLocalActivityManager().getActivity(tabId))).getScoreActivity().updateView();
}
if (tabId.equals("1")){ //driving activity
if (Utils.tabImage == null) {
//create the static image of the tabbar here
Bitmap tabImage = Bitmap.createBitmap(getTabHost().getTabWidget().getWidth(), getTabHost().getTabWidget().getHeight(), Bitmap.Config.RGB_565);
getTabHost().getTabWidget().draw(new Canvas(tabImage));
Utils.tabImage = tabImage;
}
//load second "tab" Activity
((DrivingActivityGroup)(getLocalActivityManager().getActivity("1"))).startDrivingActivity();
}
if (!tabId.equals("2")){
if (getLocalActivityManager().getActivity("2") != null){
if (((ScoreActivityGroup)getLocalActivityManager().getActivity("2")).getCurrentActivity() instanceof ScoreDetailsActivity){
//dismiss Conseil Dialog if it exists
((ScoreDetailsActivity)(((ScoreActivityGroup)getLocalActivityManager().getActivity("2")).getCurrentActivity())).dismissConseilDialog();
}
}
}
}
/**
* This method starts an activity with a given animation (ex: bottom-top)
* Used for info activities
*
* This action is placed here because the animations are ignored if done
* from child activities of the MenuTabActivity.
*
* @param clazz
* @param enterAnim
* @param exitAnim
* @param intentExtra
*/
public void startActivityWithOverridePendingTransition(Class<?> clazz, int enterAnim, int exitAnim, Integer intentExtra){
final Intent intent = new Intent(this, clazz);
if ( intentExtra != null ){
intent.putExtra("com.renault.Intent", intentExtra);
}
startActivity(intent);
overridePendingTransition(enterAnim, exitAnim);
}
public void onDestroy(){
super.onDestroy();
if (Main.monitoringHasStarted) {
Main.DriveBusinessService.stopMonitoring();
ScoringModelPojo.saveToBundle(getApplicationContext());
}
Main.monitoringHasStarted = false;
SettingsModel.saveToBundle(getApplicationContext());
}
} `
这是 tabwidget:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight = "1"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background = "@color/grayFond"
android:layout_weight = "0"/>
</LinearLayout>
</TabHost>
你们中有人遇到过标题中提到的问题吗?
Here's the code:
public class MenuTabActivity extends TabActivity implements OnTabChangeListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_layout);
TabHost tb = getTabHost();
TabHost.TabSpec spec = null;
Intent intent = null;
// My Profile tab
intent = new Intent(this, MyProfileActivityGroup.class);
View myProfileView = LayoutInflater.from(this).inflate(R.layout.button_profil, null);
spec = tb.newTabSpec("0").setIndicator(myProfileView).setContent(intent);
tb.addTab(spec);
// Driving tab
intent = new Intent(this, DrivingActivityGroup.class);
View drivingView = LayoutInflater.from(this).inflate(R.layout.button_conduite, null);
spec = tb.newTabSpec("1").setIndicator(drivingView).setContent(intent);
tb.addTab(spec);
// Score Tab
intent = new Intent(this, ScoreActivityGroup.class);
View scoreView = LayoutInflater.from(this).inflate(R.layout.button_score, null);
spec = tb.newTabSpec("2").setIndicator(scoreView).setContent(intent);
tb.addTab(spec);
// Advices Tab
intent = new Intent(this, AdvicesActivity.class);
View advicesView = LayoutInflater.from(this).inflate(R.layout.button_conseils, null);
spec = tb.newTabSpec("3").setIndicator(advicesView).setContent(intent);
tb.addTab(spec);
tb.setOnTabChangedListener(this);
Main.tabBar = tb;
tb.setCurrentTab(0);
}
@Override
public void onTabChanged(String tabId) {
if (tabId.equals("2")){
//refresh third tab
((ScoreActivityGroup)(getLocalActivityManager().getActivity(tabId))).getScoreActivity().updateView();
}
if (tabId.equals("1")){ //driving activity
if (Utils.tabImage == null) {
//create the static image of the tabbar here
Bitmap tabImage = Bitmap.createBitmap(getTabHost().getTabWidget().getWidth(), getTabHost().getTabWidget().getHeight(), Bitmap.Config.RGB_565);
getTabHost().getTabWidget().draw(new Canvas(tabImage));
Utils.tabImage = tabImage;
}
//load second "tab" Activity
((DrivingActivityGroup)(getLocalActivityManager().getActivity("1"))).startDrivingActivity();
}
if (!tabId.equals("2")){
if (getLocalActivityManager().getActivity("2") != null){
if (((ScoreActivityGroup)getLocalActivityManager().getActivity("2")).getCurrentActivity() instanceof ScoreDetailsActivity){
//dismiss Conseil Dialog if it exists
((ScoreDetailsActivity)(((ScoreActivityGroup)getLocalActivityManager().getActivity("2")).getCurrentActivity())).dismissConseilDialog();
}
}
}
}
/**
* This method starts an activity with a given animation (ex: bottom-top)
* Used for info activities
*
* This action is placed here because the animations are ignored if done
* from child activities of the MenuTabActivity.
*
* @param clazz
* @param enterAnim
* @param exitAnim
* @param intentExtra
*/
public void startActivityWithOverridePendingTransition(Class<?> clazz, int enterAnim, int exitAnim, Integer intentExtra){
final Intent intent = new Intent(this, clazz);
if ( intentExtra != null ){
intent.putExtra("com.renault.Intent", intentExtra);
}
startActivity(intent);
overridePendingTransition(enterAnim, exitAnim);
}
public void onDestroy(){
super.onDestroy();
if (Main.monitoringHasStarted) {
Main.DriveBusinessService.stopMonitoring();
ScoringModelPojo.saveToBundle(getApplicationContext());
}
Main.monitoringHasStarted = false;
SettingsModel.saveToBundle(getApplicationContext());
}
}
`
Here's the tabwidget:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight = "1"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background = "@color/grayFond"
android:layout_weight = "0"/>
</LinearLayout>
</TabHost>
Did any of you come across the issue mentioned in the title?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现出了什么问题。一定是里面有bug。在清单文件中,我没有状态栏和全屏。当将状态栏重新引入屏幕时,(无全屏)它按预期工作。也许这对某人有帮助。
附言。这应该作为 ANDROID 的错误提交。 (在2.1中测试)
I found out what was wrong. It must be a bug in there. In the manifest file I had no status bar and full screen. When introducing the status bar back into the screen, (NO FULLSCREEN) it worked as it should. Maybe this helps someone.
PS. This should be filed as a bug with ANDROID. (tested in 2.1)