下面列出了怎么用android.support.v4.widget.SlidingPaneLayout的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sliding_pane_layout);
mSlidingLayout = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout);
mList = (ListView) findViewById(R.id.left_pane);
mContent = (TextView) findViewById(R.id.content_text);
mSlidingLayout.setPanelSlideListener(new SliderListener());
mSlidingLayout.openPane();
mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
Shakespeare.TITLES));
mList.setOnItemClickListener(new ListItemClickListener());
mActionBar = createActionBarHelper();
mActionBar.init();
mSlidingLayout.getViewTreeObserver().addOnGlobalLayoutListener(new FirstLayoutListener());
}
private void setPortraitMode()
{
SlidingPaneLayout.LayoutParams params = (SlidingPaneLayout.LayoutParams) rightContainer.getLayoutParams();
params.width = KlyphDevice.getDeviceWidth();// rightContainerWidth;
// params.leftMargin = paddingLeft;
params.rightMargin = 0;
rightContainer.setLayoutParams(params);
params = (SlidingPaneLayout.LayoutParams) leftContainer.getLayoutParams();
params.width = leftContainerWidth;
params.leftMargin = 0;
params.rightMargin = 0;
leftContainer.setLayoutParams(params);
slidingPane.requestLayout();
}
private void initViews(Bundle savedInstanceState) {
mSlidingPane = (SlidingPaneLayout) findViewById(R.id.sliding_pane);
mSlidingPane.setShadowResource(R.drawable.drawer_shadow);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.pane1, UserFragment.newInstance(mUsername), "pane1").commit();
getSupportFragmentManager().beginTransaction().add(R.id.pane2, UserActionsFragment.newInstance(mUsername, UserActionsFragment.TYPE_ALL), "pane1").commit();
}
mSlidingPane.openPane();
}
private void injectLayout() {
// for panel
mSlidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout);
mEmotions = (GridView) findViewById(R.id.emotions);
mEmotions.setAdapter(new EmotionsAdapter(this));
mEmotions.setOnItemClickListener(this);
mSlidingPaneLayout.setPanelSlideListener(new SliderListener());
mSlidingPaneLayout.openPane();
mSlidingPaneLayout.getViewTreeObserver().addOnGlobalLayoutListener(new FirstLayoutListener());
// for tweet
mAvatar = (ImageView) findViewById(R.id.avatar);
mScreenName = (TextView) findViewById(R.id.screen_name);
mText = (EditText) findViewById(R.id.text);
mLocationMarker = findViewById(R.id.location_marker);
// set data to layout...
new AsyncQueryHandler(getContentResolver()) {
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
if (cursor.moveToNext()) {
Picasso.with(ComposeTweetActivity.this)
.load(cursor.getString(cursor.getColumnIndex(User.avatar_large)))
.placeholder(R.drawable.error)
.error(R.drawable.error)
.into(mAvatar);
mScreenName.setText("@" + cursor.getString(cursor.getColumnIndex(User.screen_name)));
}
cursor.close();
}
}.startQuery(0, null,
CatnutProvider.parse(User.MULTIPLE, mApp.getAccessToken().uid),
new String[]{User.avatar_large, User.screen_name}, null, null, null);
// other stuffs...
mText.addTextChangedListener(this);
}
public static BaseDSL.ViewClassResult slidingPaneLayout() {
return BaseDSL.v(SlidingPaneLayout.class);
}
public static Void slidingPaneLayout(Anvil.Renderable r) {
return BaseDSL.v(SlidingPaneLayout.class, r);
}
public static Void panelSlideListener(SlidingPaneLayout.PanelSlideListener arg) {
return BaseDSL.attr("panelSlideListener", arg);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
//通过反射来改变SlidingPanelayout的值
try {
slidingPaneLayout = new SlidingPaneLayout(this);
Field f_overHang = SlidingPaneLayout.class.getDeclaredField("mOverhangSize");
f_overHang.setAccessible(true);
f_overHang.set(slidingPaneLayout, 0);
slidingPaneLayout.setPanelSlideListener(this);
slidingPaneLayout.setSliderFadeColor(getResources().getColor(android.R.color.transparent));
} catch (Exception e) {
e.printStackTrace();
}
super.onCreate(savedInstanceState);
mFileTemp = new File(getCacheDir(), WINDOWBITMAP);
defaultTranslationX = dip2px(defaultTranslationX);
shadowWidth = dip2px(shadowWidth);
//behindframeLayout
FrameLayout behindframeLayout = new FrameLayout(this);
behindImageView = new ImageView(this);
behindImageView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
behindframeLayout.addView(behindImageView, 0);
//containerLayout
LinearLayout containerLayout = new LinearLayout(this);
containerLayout.setOrientation(LinearLayout.HORIZONTAL);
containerLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent));
containerLayout.setLayoutParams(new ViewGroup.LayoutParams(getWindowManager().getDefaultDisplay().getWidth() + shadowWidth, ViewGroup.LayoutParams.MATCH_PARENT));
//you view container
frameLayout = new FrameLayout(this);
frameLayout.setBackgroundColor(getResources().getColor(android.R.color.white));
frameLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
//add shadow
shadowImageView = new ImageView(this);
shadowImageView.setBackgroundResource(R.drawable.parallax_swipe_back_shadow);
shadowImageView.setLayoutParams(new LinearLayout.LayoutParams(shadowWidth, LinearLayout.LayoutParams.MATCH_PARENT));
containerLayout.addView(shadowImageView);
containerLayout.addView(frameLayout);
containerLayout.setTranslationX(-shadowWidth);
//添加两个view
slidingPaneLayout.addView(behindframeLayout, 0);
slidingPaneLayout.addView(containerLayout, 1);
}
public SlidingPaneLayoutAssert(SlidingPaneLayout actual) {
super(actual, SlidingPaneLayoutAssert.class);
}