我追捕每个教程,以实现这项非常简单的实施工作。一切看起来都合适,它应该可以工作,但是当我把它装在我的手机上时,它并没有做出该死的事情。任何帮助,将不胜感激。这是MainActivity和activity_main.xml:
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.widget.SlidingPaneLayout;
import android.view.View;
public class MainActivity extends Activity {
SlidingPaneLayout paneLayout;
SlidingPaneLayout.PanelSlideListener listener;
FragmentTransaction transactor;
android.app.FragmentManager manager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//decs
paneLayout = (SlidingPaneLayout) findViewById(R.id.pain);
listener = new PaneListener();
transactor = getFragmentManager().beginTransaction();
manager = getFragmentManager();
//impl
transactor.add(R.id.fragment_bottom_pane, new BottomPane());
transactor.add(R.id.fragment_top_pane, new TopPane());
transactor.commit();
paneLayout.setPanelSlideListener(listener);
}
private class PaneListener implements SlidingPaneLayout.PanelSlideListener {
@Override
public void onPanelSlide(View panel, float slideOffset) {
//stuff
}
@Override
public void onPanelOpened(View panel) {
manager.findFragmentById(R.id.fragment_bottom_pane).setHasOptionsMenu(true);
manager.findFragmentById(R.id.fragment_bottom_pane).setHasOptionsMenu(false);
}
@Override
public void onPanelClosed(View panel) {
manager.findFragmentById(R.id.fragment_bottom_pane).setHasOptionsMenu(false);
manager.findFragmentById(R.id.fragment_bottom_pane).setHasOptionsMenu(true);
}
}
/*
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
*/
}
的xml:
<android.support.v4.widget.SlidingPaneLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.sonfluence.app.MainActivity"
android:id="@+id/pain">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.sonfluence.app.BottomPane"
android:id="@+id/fragment_bottom_pane"
/>
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.sonfluence.app.TopPane"
android:id="@+id/fragment_top_pane"
/>
</android.support.v4.widget.SlidingPaneLayout>
我知道这是愚蠢的事,只是不知道是什么。请帮忙!感谢
答案 0 :(得分:0)
检查此项目:https://github.com/gabrielemariotti/androiddev/tree/master/SlidingPaneLayout 这是一个解决您问题的工作示例。