0
ボタンをクリックするとフラグメントを開くNavigationDrawerがあります。しかし、今、私はこれらの断片の一つでタブホストを作る必要があります。私はTabHostで働いたことがなく、フラグメント内の1つのTabHostでスワイプ効果を実装する方法を説明するトピックは見つかりません。それまではタブホストが設定されていましたが、何の効果もありません。あなたに私にそれをどうやって説明することができれば、感謝しています。あなたのレイアウトファイルfragments_pack
でフラグメント内のTabHostでのスワイプ効果
PacksFragment.java
package studio.com.archeagemanager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;
import android.widget.TextView;
/**
* A simple {@link Fragment} subclass.
*/
public class PacksFragment extends Fragment {
TabHost tabHost;
public PacksFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_packs, container, false);
TabHost host = (TabHost) view.findViewById(R.id.tabhost);
host.setup();
//Tab 1
TabHost.TabSpec spec = host.newTabSpec("Tab One");
spec.setContent(R.id.nuia);
spec.setIndicator("NUIA");
host.addTab(spec);
//Tab 2
spec = host.newTabSpec("Tab two");
spec.setContent(R.id.haranya);
spec.setIndicator("HARANYA");
host.addTab(spec);
//Tab 3
spec = host.newTabSpec("Tab three");
spec.setContent(R.id.oceanic);
spec.setIndicator("OCEANIC");
host.addTab(spec);
//Tab 4
spec = host.newTabSpec("Tab four");
spec.setContent(R.id.auroria);
spec.setIndicator("AURORIA");
host.addTab(spec);
for (int i=0; i<4; i++) {
View tabView = host.getTabWidget().getChildTabViewAt(i);
tabView.setPadding(0, 0, 0, 0);
TextView tv = (TextView)tabView.findViewById(android.R.id.title);
tv.setSingleLine();
tv.setTextSize(14);
}
return view;
}
}