我正在我的应用程序中使用选项卡活动。
每个标签打开一个片段,如下所示:
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class PagerAdapterReceiver extends FragmentStatePagerAdapter {
int countTabs;
public PagerAdapterReceiver(FragmentManager fm, int countTabs) {
super(fm);
this.countTabs = countTabs;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
Receiver_Tab1 tab1 = new Receiver_Tab1();
return tab1;
case 1:
Receiver_Tab2 tab2 = new Receiver_Tab2();
return tab2;
case 2:
Receiver_Tab3 tab3 = new Receiver_Tab3();
return tab3;
default:
return null;
}
}
@Override
public int getCount() {
return countTabs;
}
}
我的目标是第二个选项卡上的“简单扩展面板”。我试图找到一个很好的例子,但是我只发现了Activitis,而不是Fragments。
你们有没有机会知道一些解决方案?
这看起来不错: https://android-arsenal.com/details/1/6433 https://github.com/florent37/ExpansionPanel
不幸的是我不是专家,所以我不知道如何将它们实现为Fragment:(
有人能帮助我吗?
我的Tab2看起来像这样的atm:
receiver_tab2.xml
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
receiver_tab2.java
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Receiver_Tab2 extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.receiver_tab2, container, false);
return view;
}
}
再次感谢您!