我想在Android上进行如下所示的相同布局 我尝试使用带有FrameLayout和NavigationView的DrawerLayout作为DrawerLayout子项,但我不知道如何在打开NavigationView时使FrameLayout的左侧出现在NavigationView的右侧。
有没有人建议如何实现这个目标?
答案 0 :(得分:0)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:id="@+id/ll_home_main"
>
<android.support.v4.view.ViewPager
android:id="@+id/pager_viewpager"
android:layout_width="fill_parent"
android:focusableInTouchMode="false"
android:elevation="5dp"
android:layout_height="fill_parent" />
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
public class HomePagerActivity extends AppCompatActivity {
public static ViewPager pager;
public MyPagerAdapter myPagerAdapter;
FrameLayout container;
Context mContext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_pager);
getSupportActionBar().hide();
initi();
}
public void initi() {
container = (FrameLayout) findViewById(R.id.container);
pager = (ViewPager) findViewById(R.id.pager_viewpager);
myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
pager.setAdapter(myPagerAdapter);
mContext = HomePagerActivity.this;
pager.setCurrentItem(1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.colorAccent));
}
pager.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
pager.setCurrentItem(1);
return true;
}
});
}
private class MyPagerAdapter extends FragmentStatePagerAdapter {
final DrawerFragment drawerFragment;
final HomeFragment homeFragment;
public MyPagerAdapter(FragmentManager fm) {
super(fm);
drawerFragment = DrawerFragment.newInstance("DrawerFragment, Instance 1");
homeFragment = HomeFragment.newInstance("dashBoardFragment");
drawerFragment.setClicktListener(clicktListener);
}
@Override
public Fragment getItem(int pos) {
switch (pos) {
case 0:
return drawerFragment;
case 1:
return homeFragment;
default:
return null;
}
}
@Override
public int getCount() {
return 2;
}
@Override
public float getPageWidth(int position) {
// TODO Auto-generated method stub
if (position == 0) {
return .8f;
}
return 1f;
}
}
public void replaceFragment()
{
myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
pager.setAdapter(myPagerAdapter);
pager.setCurrentItem(1);
}
答案 1 :(得分:0)