我是新来的安卓程序员。我想让滑块变成左边或右边的片段。例如,当按钮单击列表片段显示和映射片段隐藏时,我在versa.First布局中添加了2个片段,并且我使用隐藏/显示而不是替换。
然而,我的碎片事务有时工作,有时不工作。例如,当点击按钮时,地图片段通过向左滑出进入(显示),列表通过向右滑出隐藏。但有时list仍然是我的框架布局。在这种情况下,当我正常地按下按钮时,会出现相反的效果,但是列表片段进入(显示)我的框架布局,它被复制了。
我如何才能解决剩余列表视图的问题。
我的代码在这里
Listview片段
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>MainActivity.java
public void onClick(View view) {
if (mapshere) {
android.support.v4.app.FragmentTransaction ft2 = getSupportFragmentManager().beginTransaction();
ft2.setCustomAnimations(R.anim.map_slide_in_right, R.anim.map_left_evade);
ft2.show(list);
ft2.hide(map);
ft2.commit();
btnList.setImageResource(R.drawable.icon_pin_menu1);
} else {
android.support.v4.app.FragmentTransaction ft2 = getSupportFragmentManager().beginTransaction();
ft2.setCustomAnimations(R.anim.map_slide_in_left, R.anim.map_right_evade);
ft2.show(map);
ft2.hide(list);
ft2.commit();
btnList.setImageResource(R.drawable.icon1);
}我的Listvie OnCreatView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.map_fragment_item_list, container, false);
// Set the adapter
mListView = (AbsListView) view.findViewById(android.R.id.list);
((AdapterView<ListAdapter>) mListView).setAdapter(getmAdapter());
mListView.setOnItemClickListener(this);
return view;
}正如我之前所说的,我已经在OnCreate函数中添加了这些片段。但我隐藏了列表片段。
发布于 2014-07-02 22:10:21
尝试使用
getSupportFragmentManager()
.beginTransaction()
// set your custom in/out animations
.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left,R.anim.slide_out_right)
// replace the content of the layout defined with R.id.content_frame by your fragment.
.replace(R.id.content_frame, fragment)
.commit();这应该可以解决多个片段实例的问题。
https://stackoverflow.com/questions/24500143
复制相似问题