我有一个Navdrawer,我的一个片段分别有两个标签和两个片段,当我用一些cardview填充我的recyclerview时,这个片段与标签重叠,我无法更改标签。
我的碎片 公共类TimeLineFragment extends Fragment实现了ActionBar.TabListener {
ArrayList<Gol_Entradas> dataset;
ArrayList<Gol_Entradas> gol_entradas;
Fragment[] fragments = new Fragment[]{
new FragmentRifas(),
new FragmentSubastas()
};
private FragmentTabHost mTabHost;
FragmentTransaction fragmentTransaction;
public TimeLineFragment() {
// es necesario el constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_time_line, container, false);
setTabs(rootView);
//probar cambiar por el parent
FragmentManager manager = getChildFragmentManager();
fragmentTransaction = manager.beginTransaction();
for(Fragment fragment : fragments)
{
fragmentTransaction.add(R.id.tabs_host_time_line,fragment).hide(fragment);
}
//fragmentTransaction.show(fragments[0]).commit();
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onDetach() {
super.onDetach();
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
private void setTabs(View rootView)
{
final FragmentTabHost mTabHost = (FragmentTabHost)rootView.findViewById(R.id.tabs_host_time_line);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.tabs_host_time_line);
mTabHost.addTab(mTabHost.newTabSpec("fragment_rifas").setIndicator("Rifas"),
FragmentRifas.class, null);
mTabHost.addTab(mTabHost.newTabSpec("fragment_subastas").setIndicator("Subastas"),
FragmentSubastas.class, null);
mTabHost.setCurrentTab(0);
mTabHost.setOnTabChangedListener(
new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
int i = mTabHost.getCurrentTab();
/*for(Fragment fragment : fragments)
{
fragmentTransaction.hide(fragment);
}
fragmentTransaction.show(fragments[i]);*/
//mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.bandera_hond);
Log.d("Hola como le va ",mTabHost.getTabWidget().getChildAt(1).getBackground().toString());
Log.i("Esta haciendo click en", "------" + i);
if (i == 0) {
//mTabHost.setCurrentTab(0);
Log.i("Inside onClick tab 0", "onClick tab");
}
else if (i ==1) {
//mTabHost.setCurrentTab(1);
Log.i("Inside onClick tab 1", "onClick tab");
}
}
}
);
}
片段儿童
public class FragmentRifas extends Fragment{
private String url_ws_rifas = "http://192.168.0.3/prueba_json/json.php";
ArrayList<Rifa> rifas ;
//variable que se enviara al server
//private Map<String,String> params ;
//cupones al aire
private Integer num_cupones_al_aire = 0;
public FragmentRifas () {
// es necesario el constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_rifas, container, false);
//inicializamos el array de rifas entradas
rifas = new ArrayList<Rifa>();
//para obtener los datos del ws
getJsonWSRifas(rootView);
// Inflate the layout for this fragment
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onDetach() {
super.onDetach();
}
public void getJsonWSRifas(View v)
{
RequestQueue queue = Volley.newRequestQueue(getActivity().getApplicationContext());
Rifa rifa = new Rifa();
StringRequest sr = new StringRequest(Request.Method.POST, url_ws_rifas, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("RESPONSE ", response);
try {
JSONArray jsonArray = new JSONArray(response);
fillRifasArray(jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("ERROR ", error.getCause().toString());
}
}){
//estos valores se mandan al server por post
@Override
protected Map<String,String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap< String, String>();
params.put("accion","0");
params.put("COD_PAIS","0");
params.put("codigoTipoEntrada","0");
params.put("numeroCuponesAlAire","0");
return params;
}
};
queue.add(sr);
RecyclerView recyclerView = (RecyclerView)v.findViewById(R.id.recyclerRifas);
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(new AdapterRifas(rifas,R.layout.row_rifa));
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setItemAnimator(new DefaultItemAnimator());
}
private void fillRifasArray(JSONArray array)
{
int length = array.length();
for(int i=0;i<length;i++ )
{
try {
//variables que se obtendran y que se insertaran en el arreglo
JSONObject jsonObject = (JSONObject)array.get(i);
Rifa rifa = new Rifa();
Log.d("Parametro:",rifa.getEncabezado() );
rifas.add(rifa);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
我的时间线布局
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tabs_host_time_line"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.goconsultores.goloyalty.activities.TimeLineFragment"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"/>
</LinearLayout>
My Fragment Rifas
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.goconsultores.goloyalty.fragments.FragmentRifas">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:elevation="-10dp"
android:scrollbars="vertical"
android:id="@+id/recyclerRifas"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
如果我把FragmentRifas放在另一个控件里面,这个控件也会重叠我的标签。
提前致谢。