团队冲刺06
团队冲刺06
今天遇到了很多的问题,有的通过查资料已经解决了,但是主要的还没有解决,太难了
成果展示:
package fragment; import android.app.Fragment; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.example.animator.knowledge_circle.R; /** * Created by animator on 2020/4/5. */ public class ConditionFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_by_condition,null); return view; } }
package fragment; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import com.example.animator.knowledge_circle.R; /** * Created by animator on 2020/4/5. */ public class MessageFragment extends Fragment { LinearLayout l1,l2; View down1,down2; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_message,null); Fragment fragment = new ConditionFragment(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.add(R.id.fragment_dy_condition, fragment); fragmentTransaction.commit(); l1 = (LinearLayout) view.findViewById(R.id.message_l1); l2 = (LinearLayout) view.findViewById(R.id.message_l2); down1 = view.findViewById(R.id.message_down1); down2 = view.findViewById(R.id.message_down2); down1.setBackgroundColor(Color.parseColor("#f43a68")); l1.setOnClickListener(l); l2.setOnClickListener(l); return view; } View.OnClickListener l = new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction();//开启事务 Fragment f = null; switch (view.getId()) { case R.id.message_l1: f = new ConditionFragment(); ft.replace(R.id.fragment_dy_condition, f); ft.commit(); down1.setBackgroundColor(Color.parseColor("#f43a68")); down2.setBackgroundColor(Color.parseColor("#f4f4f4")); break; case R.id.message_l2: f = new InfoFragment(); ft.replace(R.id.fragment_dy_condition, f); ft.commit(); down1.setBackgroundColor(Color.parseColor("#f4f4f4")); down2.setBackgroundColor(Color.parseColor("#f43a68")); break; } } }; }
截图: