我正在我的应用程序中创建一个滑动菜单抽屉...问题是当我滑动菜单时它正在滑动标题太多我只想让内容随滑块移动。我该如何防止标题移动。我正在为我的代码使用片段:
MainActivity:
setContentView(R.layout.layout_home);
ButterKnife.inject(this);
btnMenu.setVisibility(View.VISIBLE);
homeScreenFragment = new HomeScreenFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.frameLayout, homeScreenFragment).commit();
// configure the SlidingMenu menu = new SlidingMenu(this);
menu=new SlidingMenu(this);
menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.menu_frame);
getSupportFragmentManager().beginTransaction()
.replace(R.id.menu_frame, new HomeNavFragment()).commit();
findViewById(R.id.imgBtnMenu).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
menu.toggle(true);
}
});
HomeScreenFragment:
public final String[] podName = new String[] { "NO Text", "NO Text",
"NO Text", "NO Text" };
public final Integer[] images = { R.drawable.pod_img1, R.drawable.pod_img2,
R.drawable.pod_img3, R.drawable.pod_img1 };
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout_homescreen, container,
false);
ButterKnife.inject(this, view);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
addItemsToListView();
}
private void addItemsToListView() {
rowItems = new ArrayList<RowItem>();
for (int i = 0; i < podName.length; i++) {
RowItem item = new RowItem(images[i], podName[i]);
// RowItem item = new RowItem(imageUrl[i], deityName[i]);
rowItems.add(item);
}
setAdapter();
}
private void setAdapter() {
CustomBaseAdapter adapter = new CustomBaseAdapter(getActivity(), rowItems);
podListView.setAdapter(adapter);
}
Navigation Fragment:
public static final String[] nav_title = new String[] { "CLE & Events",
"Pictorial Roster", "Publications", "On-Demand CLE", "Court Info",
"LBA Alerts", "My Profile", "Notification Settings",
"App Support & Feedback", "Share this App", "Developer", " ", " " };
public static final int[] nav_icon = { R.drawable.ic_menu_calender,
R.drawable.ic_menu_roster, R.drawable.ic_menu_publication,
R.drawable.ic_menu_filebox, R.drawable.ic_menu_court,
R.drawable.ic_menu_bubble, R.drawable.ic_menu_profile,
R.drawable.ic_menu_reminder, R.drawable.ic_menu_share,
R.drawable.ic_menu_developer, R.drawable.ic_menu_developer,
R.drawable.ic_menu_developer };
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout_homescreen, container,
false);
ButterKnife.inject(this, view);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
setAdapter();
/*addItemsToListView();*/
}
private void setAdapter() {
NavigationMenuAdapter adapter = new NavigationMenuAdapter(getActivity(),nav_title,nav_icon);
podListView.setAdapter(adapter);
}
Xml:
layout_home:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include
android:id="@+id/header_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
layout="@layout/include_header" />
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/header_home">
</FrameLayout>
</RelativeLayout>
layout_homescreen
<ListView
android:id="@+id/podListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent" >
</ListView>
</LinearLayout>
menu.xml
答案 0 :(得分:1)
由于您想要使用sidepanel移动内容区域+ ActionBar应该保持静态,最好的方法是实现v4小部件 SlidingPaneLayou t(android.support.v4.widget.SlidingPaneLayout)。
here是一个很好的例子,解释了如何实现SlidingPaneLayout
请仔细阅读Developer's site以获得正确理解。
希望它有所帮助.. !! :)