SlidingPaneLayout不会滑动

时间:2014-07-18 11:29:30

标签: android android-layout android-fragments slidingpanelayout

slidingPaneLayout不会滑动!

pane.isSlideable() false ! 我以这种方式膨胀布局:

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

                // Inflate the layout for this fragment
                slidingView =  inflater.inflate(R.layout.available_nodes_fragment, container, false);


                SlidingPaneLayout pane = (SlidingPaneLayout)slidingView.findViewById(R.id.sliding_pane_layout);

                Fragment fragmentA = new ListNodesFragment();
                FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
                transaction.add(R.id.child_fragmentA, fragmentA );

                Fragment fragmentB = new ReserveNodesFragment();
                transaction.add(R.id.child_fragmentB, fragmentB);

                transaction.commit();

                //pane.setPanelSlideListener(new SliderListener());
                pane.openPane();
                Log.i("Available Nodes","PANE IS SLIDABLE" + pane.isSlideable());

                return slidingView;

}

我膨胀的 available_nodes_fragment 布局是:

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


         <LinearLayout
          android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
           <FrameLayout
          android:id="@+id/child_fragmentA"
          android:layout_width="180dp"
          android:layout_height="match_parent"
          android:layout_gravity="left" />

           <FrameLayout
         android:id="@+id/child_fragmentB"
         android:layout_width="100dp"
         android:layout_height="match_parent"
         android:layout_gravity="right" />
         </LinearLayout>


</android.support.v4.widget.SlidingPaneLayout>

我不知道为什么SlidingPaneLayout不会滑动。我不知道这个问题是否与我使用嵌套片段的事实有关。


我有一些进步。

我更改了 available_nodes_fragment 布局文件:

<?xml version="1.0" encoding="utf-8"?>  

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/reserve_nodes"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:descendantFocusability="beforeDescendants"
        android:focusableInTouchMode="true"
        android:orientation="vertical" >

      <android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/sliding_pane_layout"
       android:layout_width="match_parent"
       android:layout_height="match_parent">
        <FrameLayout
            android:id="@+id/child_fragmentA"
            android:layout_width="wrap_content"
            android:layout_height="200dp"
            android:layout_gravity="left"
            android:layout_marginRight="25dp"           
            android:background="#A588DC" />

        <FrameLayout
            android:id="@+id/child_fragmentB"
            android:layout_width="wrap_content"
            android:layout_height="200dp"
            android:background="#B6D4D3"
            android:layout_gravity="right" />

      </android.support.v4.widget.SlidingPaneLayout>


        <Button 
            android:id="@+id/btnReserveNodes"
            android:layout_width="wrap_content"
            android:layout_height="70dp"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="30dp"
            android:text="Reserve"/>
</RelativeLayout>

现在,SlidePaneLayout布局会滑动。我不知道为什么。当我将FrameLayouts的固定layout_width更改为wrap_content时,SlidePaneLayout开始滑动。

我现在的问题是我希望带有id = &#34; child_fragmentA&#34; 的FrameLayout与ListView水平地获得屏幕的 30%。我没有找到办法,因为FrameLayout不支持权重。

我还提供了ListNodesFragment和ReserveNodesFragment的代码。

ListFragments.java

public class ListNodesFragment extends Fragment {



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

         View listNodesView = inflater.inflate(R.layout.nodes_categories_listview, container, false);

         String[] items = { getResources().getString(R.string.orbit_nodes),
            getResources().getString(R.string.grid_nodes),
            getResources().getString(R.string.usrp_nodes),
            getResources().getString(R.string.diskless_nodes), 
            getResources().getString(R.string.icarus_nodes) ,
            getResources().getString(R.string.base_station)
          };

         ListView nodesListView = (ListView) listNodesView.findViewById(R.id.nodes_list);

         ArrayAdapter<String> adapt = new ArrayAdapter<String>(getActivity(), R.layout.nodes_categories_listview_item, items);
         nodesListView.setAdapter(adapt);
         return listNodesView;


     }

}

ReserveNodesFragment.java

public class ReserveNodesFragment extends Fragment {


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

            View reserveNodesView = inflater.inflate(R.layout.reserve_nodes_fragment, container, false);
              TextView txtView = (TextView) reserveNodesView.findViewById(R.id.textView1);
              txtView.setText("fragment 2");
            return reserveNodesView;
       }


}

0 个答案:

没有答案