【发布时间】:2014-08-06 03:21:19
【问题描述】:
我目前正在尝试使用 ListView 作为主布局和相对布局作为滑动布局来实现AndroidSlidingUpPanel。这是我正在使用的 XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/lib/com.sothree.slidinguppanel"
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bar_background"
android:gravity="bottom"
android:orientation="horizontal"
sothree:collapsedHeight="40dp" >
<ListView
android:id="@+id/song_list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="42"
android:fastScrollEnabled="true" />
<RelativeLayout
android:id="@+id/bottom_bar_preview"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@color/bar_background"
android:orientation="horizontal" >
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</LinearLayout>
我的问题是列表的内容只有在展开和折叠滑动布局一次后才可见。 SlidingUpPanelLayout 本身嵌入到位于 FragmentPagerAdapter 内的 Fragment 中。我还注意到列表的内容在滑出两个片段后消失了(然后又滑回来)。 这是片段的代码:
public abstract class Songs extends Fragment {
protected ArrayList<String> elements;
protected SonglistAdapter adapter;
public Songs(ArrayList<String> es) {
elements = es;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LinearLayout rootView = (LinearLayout) inflater.inflate(R.layout.list_songlist, container, false);
ListView lview = (ListView) rootView.findViewById(R.id.song_list);
adapter = new SonglistAdapter(inflater, elements);
lview.setAdapter(adapter);
return rootView;
}
}
这里是它的适配器:
public class SonglistAdapter extends BaseAdapter {
private ArrayList<String> elements;
private LayoutInflater inflater;
public SonglistAdapter(LayoutInflater infl, ArrayList<String> es) {
elements = es;
inflater = infl;
}
@Override
public int getCount() {
return elements.size();
}
@Override
public Object getItem(int i) {
return elements.get(i);
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout layer = (RelativeLayout) inflater.inflate(R.layout.list_songlist_item, parent, false);
// fill current item with information
TextView view = (TextView) layer.findViewById(R.id.song_title);
view.setText(elements.get(position));
return layer;
}
}
我在 FragmentPagerAdapter 中创建 Fragment 如下:
ArrayList<String> arr = new ArrayList<String>();
arr.add("Hello");
arr.add("Bye");
ContentHandler.overviewFragment = new Overview(arr);
'ContentHandler.overviewFragment' 然后在'public Fragment getItem(int index)' 中返回(以通常的方式)。
我尝试查看 AndroidSlidingUpPanel 的源代码,并认为错误可能在“受保护的 void onLayout(boolean changed, int l, int t, int r, int b)” 函数中的 this 文件中,但我无法找到启动调用和滑动面板重新折叠调用之间的任何区别。 所以我的问题是,你们中是否有人知道我的实现有什么问题。
PS:由于这是我第一次提交,我很乐意以任何可能的方式改进我的帖子!
【问题讨论】:
标签: android android-fragments slidingmenu