我遇到了障碍,我的标签式布局与其内容重叠。我目前正在创建一个Android应用。这是第一个选项卡打开时。 (链接到下面的图片):
当我打开第二个标签时会发生这种情况(链接到下面的图片):
您可能会注意到“Button”按钮与MainActivity重叠。那是我的问题。我不希望它们重叠。我只想让按钮显示其他活动(没有重叠)。这是我的MainActivity.java代码的一部分:
package com.example.currencyconverter;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
ActionBar actionBar = getActionBar();
actionBar.setSubtitle("Created By Rohit Nandakumar");
actionBar.setTitle("Currency Converter");
// Specify that tabs should be displayed in the action bar.
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab Frag1 = actionBar.newTab().setText("Converter");
ActionBar.Tab Frag2 = actionBar.newTab().setText("Currencies");
ActionBar.Tab Frag3 = actionBar.newTab().setText("News");
Fragment fragment1 = new Fragment1();
Fragment fragment2 = new Fragment2();
Fragment fragment3 = new Fragment3();
Frag1.setTabListener(new MyTabsListener(fragment1));
Frag2.setTabListener(new MyTabsListener(fragment2));
Frag3.setTabListener(new MyTabsListener(fragment3));
actionBar.addTab(Frag1);
actionBar.addTab(Frag2);
actionBar.addTab(Frag3);
这是Fragment1.java代码:
package com.example.currencyconverter;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment1 extends Fragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_main, container, false);
}
}
这是我的Fragment2.java代码:
package com.example.currencyconverter;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment2 extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment2, container, false);
}
}
这是我的MyTabsListener.java文件:
package com.example.currencyconverter;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Fragment;
import android.app.FragmentTransaction;
public class MyTabsListener implements TabListener {
public Fragment fragment;
public MyTabsListener(Fragment fragment) {
this.fragment = fragment;
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
}
有什么问题?我究竟做错了什么。我搜索了谷歌,但我找不到解决方案。非常感谢任何帮助。