gpt4 book ai didi

java - 在 SlidingPaneLayout 实现中 Pane 始终打开

转载 作者:行者123 更新时间:2023-12-01 18:25:00 25 4
gpt4 key购买 nike

我下面的代码的问题是默认情况下总是打开 Pane ,不知道为什么。显然,我不希望默认打开 Pane (子 Pane )。仅当用户单击 lv_schedule 时,该 Pane 才会打开。因此,当 fragment 加载时,我必须先滑出 Pane 才能看到 lv_schedule。

这是 XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scheduledblocks_sliding_pane_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<LinearLayout
android:id="@+id/ll_left_pane_scheduled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<ListView
android:id="@+id/lv_schedule"
android:layout_width="1000dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_marginRight="0dp"
/>

</LinearLayout>

<!-- Framelayout to display Fragments -->

<FrameLayout
android:id="@+id/frame_container_scheduledblocksslidingpanedetailview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp" />

这是 JAVA 文件:

public class Fragment_allScheduledBlocks extends Fragment implements
View.OnClickListener, OnItemClickListener {

private Handler handler;

private ActionBarHelper mActionBar;

private Thread thread = new Thread();

public Fragment_allScheduledBlocks() {
}

@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

mLogger.printToLog(Constants.LOG_ENTRY,
" onCreateView of Fragment_scheduled_blocks.java",
Constants.TAG_ALL);

v = inflater.inflate(R.layout.fragment_scheduled_blocks, container,
false);

mSlidingLayout = (SlidingPaneLayout) v
.findViewById(R.id.scheduledblocks_sliding_pane_layout);
mSlidingLayout.setPanelSlideListener(new SliderListenerSchBlocks());
mSlidingLayout.openPane();


lv_scheduled = (ListView) v.findViewById(R.id.lv_scheduled);
lv_scheduled.setOnItemClickListener(this);

mActionBar = createActionBarHelper();
mActionBar.init();

return v;
}


/**
* This panel slide listener updates the action bar accordingly for each
* panel state.
*/
private class SliderListenerSchBlocks extends
SlidingPaneLayout.SimplePanelSlideListener {
@Override
public void onPanelOpened(View panel) {
mActionBar.onPanelOpened();
Log.v(Constants.TAG, "in onPanelOPened inside SliderListener");
getActivity().setTitle("LISTVIEW BLOCKS");

mPrefs.printAllMySharedPrefs(getActivity().getApplicationContext());
}

@Override
public void onPanelClosed(View panel) {
mActionBar.onPanelClosed();
Log.v(Constants.TAG, "in onPanelClosed inside SliderListener");
mPrefs.printAllMySharedPrefs(getActivity().getApplicationContext());
}

@Override
public void onPanelSlide(View panel, float slideOffset) {
// TODO Auto-generated method stub
super.onPanelSlide(panel, slideOffset);
}
}




@Override
public void onClick(View v) {
// TODO Auto-generated method stub

}

private class ActionBarHelper {
public void init() {
}

public void onPanelClosed() {
}

public void onPanelOpened() {
}

public void onFirstLayout() {
}

public void setTitle(CharSequence title) {
}
}

/*
* Create a compatible helper that will manipulate the action bar if
* available.
*/
private ActionBarHelper createActionBarHelper() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// return new ActionBarHelperICS();
return new ActionBarHelper();
} else {
return new ActionBarHelper();
}
}

}

最佳答案

如果您想通过导航图标打开 Pane ,则可以使用此:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pane);

layout = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout);

getToolbar().setNavigationIcon(R.drawable.ic_menu_white_24dp);
getToolbar().setNavigationOnClickListener(this);
}

@Override
public void onClick(View view) {
if (layout != null) {
if (!layout.isOpen()) {
layout.openPane();
} else {
layout.closePane();
}
}
}

干杯,编码愉快。 ;)

关于java - 在 SlidingPaneLayout 实现中 Pane 始终打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26505001/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com