A summary of some knowledge points encountered in the educational system project
1. Activity jump to Activity
method one
Intent intent = new Intent(当前Activity.this, 目标Activity.class);
putExtra("标志",数据);//当需要在跳转时传递数据用这个语句
startActivity(intent);
2. Activity jump to Fragment
method one
Intent intent = new Intent(Activity.this ,Fragment所在Activity.class);
putExtra("标志",int); // 用来标记要跳转的是哪个fragment
startActivity(intent);
Method Two
Intent intent = new Intent(Activity.this ,Fragment所在Activity.class);
startActivity(intent)
在Fragment所在Activity里边处理切换fragment的逻辑
3. Fragment jump to Activity
method one
Intent intent = new Intent(getActivity(), 目标Activity.class);
startActivity(intent);
4. Code generation View
LinearLayout
LinearLayout lly = new LinearLayout(getContext()); // 获取上下文context
lly.setOrientation(LinearLayout.VERTICAL); //方向竖直
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT ,firstHeight); //设置宽和高
// 可以通过这个addRule添加规则,第一个参数为方位,第二个参数为相对于哪个view的id
params.addRule(RelativeLayout.RIGHT_OF ,left_top_Text.getId());
lly.setLayoutParams(params);
ScrollView
Note: ScrollView can only have one child view (of course you can wrap as many views as you want with Layout)
ScrollView scrollView = new ScrollView(getContext());
scrollView.setId(R.id.scrollView);
LayoutParams rlp_sv = new LayoutParams(LayoutParams.MATCH_PARENT , LayoutParams.WRAP_CONTENT);
//如果你需要设置它相对于某个控件的位置就可以使用下面这条语句和上面Layout的用法一样
rlp_sv.addRule(RelativeLayout.BELOW ,left_top_Text.getId());
scrollView.setLayoutParams();
FramLayout
FraeLayout frameLayout = new FrameLayout(getContext());
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT );
frameLayout.setLayoutParams(layoutParams);
TextView
TextView tv = new TextView(getContext());
tv.setHeight(height);
tv.setWidth(width);
tv.setTextColor(getResources().getColor(R.color.text1_color)); //这里引用了一个values中colors.xml里的自定义颜色
tv.setTextSize(14);
tv1.setGravity(CENTER_HORIZONTAL); //在LinearLayout的VERTICAL条件下
tv.setText("内容") ;
ProgressDialog
The encapsulated opening and closing methods of ProgressDialog are directly given here!
//开启
private void showPressDialog(){
if(progressDialog == null){
progressDialog = new ProgressDialog(this);
progressDialog .setMessage("正在加载...");
progressDialog.setCanceledOnTouchOutside(false);
}
progressDialog.show();
}
//关闭
private void closeProgressDialog(){
if(progressDialog != null){
progressDialog.dismiss();
}
}
4.Fragment switch Fragment
//import.support.v4.app.FragmentTransaction;
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction;
transaction.replace(R.id.frame_content, new CenterFragment());
transaction.commit();
5. Specify x, y coordinates to generate view
LayoutParams params = new LayoutParams(x,y);//x,y分别为距离左边屏幕和上边屏幕的距离
控件对象.setLayoutParams(params);
6. Custom Background Drawable
Here are just some of the syntaxes I use
<?xml version="1.0" encoding="utf-8">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="0dp"> // 一个item相当于一个独立的drawable
<shape android:shape="rectangle"> //shape表示形状
<solid android:color = "#344AF7"/> //solid表示纯色填充,通过android:color设置颜色
<corners android:topRightRadius ="10dp" //为右上角设定角度(圆角)
android:topLeftRadius ="10dp"/> //为左上角设定角度(圆角)
</shape>
</item>
<item android:bottom = "0.5dp" //与上边的距离
android:right="0.5dp" //与右边的距离
android:left="0.5dp" > //与左边的距离
<shape android:shape="rectangle">
<corners android:topRightRadius ="10dp"
android:topLeftRadius ="10dp"/>
<solid android:color ="#cbeff6"/>
</shape>
</item>
7.viewPager+tablayout
This previous blog has a link here: [code of viewPager+tabLayout] Explanation of
viewPager+tabLayout ( https://blog.csdn.net/sliverbullets/article/details/79437951 )