Android动态布局framelayout

功能说明
最近碰到一个需求,要求在网页端拖控件,动态配置app控件的模块,大小和位置,显示不同的功能,然后在app大屏展示。
技术难点:
1.动态控件位置和大小难调,会出现布局混乱,位置错乱等问题
2.动态控件样式多样,有相册,有新闻列表,有个人信息展示,有轮播图等等,解决方案就是用cardview嵌入frame layout,引入fragment,独立布局

代码说明:
step1:引入依赖,用gson进行json解析~\app\build.gradle
step2:清单文件,用于新增application,获取全局context~\app\src\main\AndroidManifest.xml
step3:主界面布局~\app\src\main\res\layout\activity_main.xml
step4:json文件,模拟后台数据,动态控制控件位置和大小~\app\src\main\assets\stu1.json
step5:同上~\app\src\main\assets\stu2.json
step6:同上~\app\src\main\assets\stu3.json
step7:全局context ~\app\src\main\java\com\example\iosdialogdemo\IvApplication.java
step8:数据bean类~\app\src\main\java\com\example\iosdialogdemo\CardBean.java
step9:动态控件设置,设置位置大小 ~\app\src\main\java\com\example\iosdialogdemo\AdaptScreenUtils.java
step10:主界面,json解析和判断控件位置大小参数设置~\app\src\main\java\com\example\iosdialogdemo\MainActivity.java
效果图
在这里插入图片描述

step1:~\app\build.gradle

    implementation 'com.google.code.gson:gson:2.8.0'

step2:~\app\src\main\AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.iosdialogdemo"><applicationandroid:name=".IvApplication"android:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.IosDialogDemo"><activity android:name=".MainActivity"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>

step3:~\app\src\main\res\layout\activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/darker_gray"android:orientation="vertical"android:padding="15dp"><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_0"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="10dp"android:visibility="gone"app:cardBackgroundColor="@android:color/holo_purple"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="10dp"android:visibility="gone"app:cardBackgroundColor="@android:color/holo_red_light"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"android:layout_margin="10dp"app:cardBackgroundColor="@android:color/holo_orange_light"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"android:layout_margin="10dp"app:cardBackgroundColor="@android:color/holo_green_dark"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"android:layout_margin="10dp"app:cardBackgroundColor="@android:color/holo_blue_dark"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"android:layout_margin="10dp"app:cardBackgroundColor="@android:color/holo_purple"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"android:layout_margin="10dp"app:cardBackgroundColor="@android:color/holo_red_light"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"android:layout_margin="10dp"app:cardBackgroundColor="@android:color/holo_orange_dark"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"android:layout_margin="10dp"app:cardBackgroundColor="@android:color/holo_purple"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_9"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"android:layout_margin="10dp"app:cardBackgroundColor="@android:color/holo_orange_light"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_10"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"android:layout_margin="10dp"app:cardBackgroundColor="@android:color/holo_green_dark"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView><androidx.cardview.widget.CardViewandroid:id="@+id/auto_card_11"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"android:layout_margin="10dp"app:cardBackgroundColor="@android:color/holo_blue_dark"app:cardCornerRadius="10dp"app:contentPadding="20dp"></androidx.cardview.widget.CardView></FrameLayout>

step4:~\app\src\main\assets\stu1.json

[{"Id": 0,"studentName": "第一个card","location": 0,"size": 11,"isShow": true},{"Id": 1,"studentName": "第二个card","location": 1,"size": 21,"isShow": true},{"Id": 2,"studentName": "第三个card","location": 2,"size": 21,"isShow": false},{"Id": 3,"studentName": "第四个card","location": 3,"size": 11,"isShow": true},{"Id": 4,"studentName": "第五个card","location": 4,"size": 11,"isShow": true},{"Id": 5,"studentName": "第六个card","location": 5,"size": 12,"isShow": true},{"Id": 6,"studentName": "第七个card","location": 6,"size": 12,"isShow": true},{"Id": 7,"studentName": "第八个card","location": 7,"size": 11,"isShow": true},{"Id": 8,"studentName": "第九个card","location": 8,"size": 11,"isShow": true},{"Id": 9,"studentName": "第十个card","location": 9,"size": 11,"isShow": false},{"Id": 10,"studentName": "第十一个card","location": 10,"size": 11,"isShow": false},{"Id": 11,"studentName": "第十二个card","location": 11,"size": 11,"isShow": true}
]

step5:~\app\src\main\assets\stu2.json

[{"Id": 0,"studentName": "第一个card","location": 0,"size": 11,"isShow": true},{"Id": 1,"studentName": "第二个card","location": 1,"size": 21,"isShow": true},{"Id": 2,"studentName": "第三个card","location": 2,"size": 21,"isShow": true},{"Id": 3,"studentName": "第四个card","location": 3,"size": 11,"isShow": false},{"Id": 4,"studentName": "第五个card","location": 4,"size": 11,"isShow": true},{"Id": 5,"studentName": "第六个card","location": 5,"size": 11,"isShow": true},{"Id": 6,"studentName": "第七个card","location": 6,"size": 12,"isShow": true},{"Id": 7,"studentName": "第八个card","location": 7,"size": 12,"isShow": true},{"Id": 8,"studentName": "第九个card","location": 8,"size": 11,"isShow": true},{"Id": 9,"studentName": "第十个card","location": 9,"size": 11,"isShow": true},{"Id": 10,"studentName": "第十一个card","location": 10,"size": 11,"isShow": false},{"Id": 11,"studentName": "第十二个card","location": 11,"size": 11,"isShow": false}
]

step6:~\app\src\main\assets\stu3.json

[{"Id": 0,"studentName": "第一个card","location": 0,"size": 11,"isShow": true},{"Id": 1,"studentName": "第二个card","location": 1,"size": 12,"isShow": true},{"Id": 2,"studentName": "第三个card","location": 2,"size": 12,"isShow": true},{"Id": 3,"studentName": "第四个card","location": 3,"size": 11,"isShow": true},{"Id": 4,"studentName": "第五个card","location": 4,"size": 11,"isShow": true},{"Id": 5,"studentName": "第六个card","location": 5,"size": 12,"isShow": false},{"Id": 6,"studentName": "第七个card","location": 6,"size": 12,"isShow": false},{"Id": 7,"studentName": "第八个card","location": 7,"size": 11,"isShow": true},{"Id": 8,"studentName": "第九个card","location": 8,"size": 11,"isShow": true},{"Id": 9,"studentName": "第十个card","location": 9,"size": 21,"isShow": true},{"Id": 10,"studentName": "第十一个card","location": 10,"size": 11,"isShow": false},{"Id": 11,"studentName": "第十二个card","location": 11,"size": 11,"isShow": true}
]

step7:~\app\src\main\java\com\example\iosdialogdemo\IvApplication.java

package com.example.iosdialogdemo;import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;import androidx.annotation.RequiresApi;import java.util.LinkedList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;public class IvApplication extends Application {public static Context context;private static IvApplication application;@Overridepublic void onCreate() {super.onCreate();context = this;application = this;}public static IvApplication getInstance() {return application;}public static Context getContext() {return context;}}

step8:~\app\src\main\java\com\example\iosdialogdemo\CardBean.java

package com.example.iosdialogdemo;public class CardBean {/*模块大小 11  12  21   22 等等模块位置     0 1 2 3 4 5 6 7 8默认所有按钮全部隐藏  然后在代码里设置显示"Id": 0,"studentName": "第一个card","location": 0,"size": 11,"isShow": true*/private int id;private String studentName;private int location;private int size;private boolean isShow;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getStudentName() {return studentName;}public void setStudentName(String studentName) {this.studentName = studentName;}public int getLocation() {return location;}public void setLocation(int location) {this.location = location;}public int getSize() {return size;}public void setSize(int size) {this.size = size;}public boolean isShow() {return isShow;}public void setShow(boolean show) {isShow = show;}
}

step9:~\app\src\main\java\com\example\iosdialogdemo\AdaptScreenUtils.java

package com.example.iosdialogdemo;import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;import androidx.annotation.NonNull;public final class AdaptScreenUtils {public static int getScreenWidth() {Resources resources = IvApplication.getContext().getResources();DisplayMetrics dm = resources.getDisplayMetrics();return dm.widthPixels;}public static int getScreenHeight() {Resources resources = IvApplication.getContext().getResources();DisplayMetrics dm = resources.getDisplayMetrics();return dm.heightPixels;}public static int getScreenItemWidth() {Resources resources = IvApplication.getContext().getResources();DisplayMetrics dm = resources.getDisplayMetrics();return dm.widthPixels / 4;}public static int getScreenItemHeight() {Resources resources = IvApplication.getContext().getResources();DisplayMetrics dm = resources.getDisplayMetrics();return dm.heightPixels / 3;}public static void getScreenHeight5(View view, int point, int widthSize, int heightSize, int widthLocation, int heightLocation) {switch (point) {case 0:FrameLayout.LayoutParams params0 = (FrameLayout.LayoutParams) view.getLayoutParams();params0.width = widthSize;params0.height = heightSize;params0.setMargins(0, 0, 0, 0);view.setLayoutParams(params0);break;case 1:FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) view.getLayoutParams();params1.width = widthSize;params1.height = heightSize;params1.setMargins(widthLocation, 0, 0, 0);view.setLayoutParams(params1);break;case 2:FrameLayout.LayoutParams params2 = (FrameLayout.LayoutParams) view.getLayoutParams();params2.width = widthSize;params2.height = heightSize;params2.setMargins(widthLocation * 2, 0, 0, 0);view.setLayoutParams(params2);break;case 3:FrameLayout.LayoutParams params3 = (FrameLayout.LayoutParams) view.getLayoutParams();params3.width = widthSize;params3.height = heightSize;params3.setMargins(widthLocation * 3, 0, 0, 0);view.setLayoutParams(params3);break;case 4:FrameLayout.LayoutParams params4 = (FrameLayout.LayoutParams) view.getLayoutParams();params4.width = widthSize;params4.height = heightSize;params4.setMargins(0, heightLocation, 0, 0);view.setLayoutParams(params4);break;case 5:FrameLayout.LayoutParams params5 = (FrameLayout.LayoutParams) view.getLayoutParams();params5.width = widthSize;params5.height = heightSize;params5.setMargins(widthLocation, heightLocation, 0, 0);view.setLayoutParams(params5);break;case 6:FrameLayout.LayoutParams params6 = (FrameLayout.LayoutParams) view.getLayoutParams();params6.width = widthSize;params6.height = heightSize;params6.setMargins(widthLocation * 2, heightLocation, 0, 0);view.setLayoutParams(params6);break;case 7:FrameLayout.LayoutParams params7 = (FrameLayout.LayoutParams) view.getLayoutParams();params7.width = widthSize;params7.height = heightSize;params7.setMargins(widthLocation * 3, heightLocation, 0, 0);view.setLayoutParams(params7);break;case 8:FrameLayout.LayoutParams params8 = (FrameLayout.LayoutParams) view.getLayoutParams();params8.width = widthSize;params8.height = heightSize;params8.setMargins(0, heightLocation * 2, 0, 0);view.setLayoutParams(params8);break;case 9:FrameLayout.LayoutParams params9 = (FrameLayout.LayoutParams) view.getLayoutParams();params9.width = widthSize;params9.height = heightSize;params9.setMargins(widthLocation, heightLocation * 2, 0, 0);view.setLayoutParams(params9);break;case 10:FrameLayout.LayoutParams params10 = (FrameLayout.LayoutParams) view.getLayoutParams();params10.width = widthSize;params10.height = heightSize;params10.setMargins(widthLocation * 2, heightLocation * 2, 0, 0);view.setLayoutParams(params10);break;case 11:FrameLayout.LayoutParams params11 = (FrameLayout.LayoutParams) view.getLayoutParams();params11.width = widthSize;params11.height = heightSize;params11.setMargins(widthLocation * 3, heightLocation * 2, 0, 0);view.setLayoutParams(params11);break;}}
}

step10:~\app\src\main\java\com\example\iosdialogdemo\MainActivity.java

package com.example.iosdialogdemo;import android.os.Bundle;
import android.util.Log;import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewTreeObserver;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;import java.lang.reflect.Type;
import java.util.List;public class MainActivity extends Activity {private List<CardBean> stuList;private int width=0;private int height=0;private String jsonString;private CardView card_0, card_1, card_2, card_3,card_4, card_5, card_6, card_7,card_8, card_9, card_10, card_11;private int[] cardInts0 = {11, 21, 0, 11,11, 12, 12, 11,11, 0, 0, 11};private Handler mHandler = new Handler(new Handler.Callback() {@Overridepublic boolean handleMessage(@NonNull Message message) {if (message.what == 100) {jsonString = (String) message.obj;Log.i("INFO", "##### Sub_json: " + ": " + jsonString);Gson gson = new Gson();//解析Type type = new TypeToken<List<CardBean>>() {}.getType();if (stuList != null) {stuList.clear();}stuList.addAll(gson.fromJson(jsonString, type));Log.e("INFO", "##### Sub_list: " + ": " + stuList);//根据传递过来的值  来控制控件是否显示if (stuList != null) {if (stuList.get(0).isShow()) {card_0.setVisibility(View.VISIBLE);} else {card_0.setVisibility(View.GONE);}if (stuList.get(1).isShow()) {card_1.setVisibility(View.VISIBLE);} else {card_1.setVisibility(View.GONE);}if (stuList.get(2).isShow()) {card_2.setVisibility(View.VISIBLE);} else {card_2.setVisibility(View.GONE);}if (stuList.get(3).isShow()) {card_3.setVisibility(View.VISIBLE);} else {card_3.setVisibility(View.GONE);}if (stuList.get(4).isShow()) {card_4.setVisibility(View.VISIBLE);} else {card_4.setVisibility(View.GONE);}if (stuList.get(5).isShow()) {card_5.setVisibility(View.VISIBLE);} else {card_5.setVisibility(View.GONE);}if (stuList.get(6).isShow()) {card_6.setVisibility(View.VISIBLE);} else {card_6.setVisibility(View.GONE);}if (stuList.get(7).isShow()) {card_7.setVisibility(View.VISIBLE);} else {card_7.setVisibility(View.GONE);}if (stuList.get(8).isShow()) {card_8.setVisibility(View.VISIBLE);} else {card_8.setVisibility(View.GONE);}if (stuList.get(9).isShow()) {card_9.setVisibility(View.VISIBLE);} else {card_9.setVisibility(View.GONE);}if (stuList.get(10).isShow()) {card_10.setVisibility(View.VISIBLE);} else {card_10.setVisibility(View.GONE);}if (stuList.get(11).isShow()) {card_11.setVisibility(View.VISIBLE);} else {card_11.setVisibility(View.GONE);}}/** 根据 json里面的size 大小  来确定 控件的 长宽* 11 12 21 22 33 */width =  AdaptScreenUtils.getScreenItemWidth();height = AdaptScreenUtils.getScreenItemHeight()* 86 / 100;Log.e("INFO", "##### Sub_size: " + width+": ===" + height);if (stuList.get(0).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_0, stuList.get(0).getLocation(), width,height,width,height);}else if (stuList.get(0).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_0, stuList.get(0).getLocation(), width,height*2,width,height);}else if (stuList.get(0).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_0, stuList.get(0).getLocation(), width*2,height,width,height);}else if (stuList.get(0).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_0, stuList.get(0).getLocation(), width*2,height*2,width,height);}else if (stuList.get(0).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_0, stuList.get(0).getLocation(), width*3,height*3,width,height);}if (stuList.get(1).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_1, stuList.get(1).getLocation(), width,height,width,height);}else if (stuList.get(1).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_1, stuList.get(1).getLocation(), width,height*2,width,height);}else if (stuList.get(1).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_1, stuList.get(1).getLocation(), width*2,height,width,height);}else if (stuList.get(1).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_1, stuList.get(1).getLocation(), width*2,height*2,width,height);}else if (stuList.get(1).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_1, stuList.get(1).getLocation(), width*3,height*3,width,height);}if (stuList.get(2).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_2, stuList.get(2).getLocation(), width,height,width,height);}else if (stuList.get(2).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_2, stuList.get(2).getLocation(), width,height*2,width,height);}else if (stuList.get(2).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_2, stuList.get(2).getLocation(), width*2,height,width,height);}else if (stuList.get(2).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_2, stuList.get(2).getLocation(), width*2,height*2,width,height);}else if (stuList.get(2).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_2, stuList.get(2).getLocation(), width*3,height*3,width,height);}if (stuList.get(3).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_3, stuList.get(3).getLocation(), width,height,width,height);}else if (stuList.get(3).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_3, stuList.get(3).getLocation(), width,height*2,width,height);}else if (stuList.get(3).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_3, stuList.get(3).getLocation(), width*2,height,width,height);}else if (stuList.get(3).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_3, stuList.get(3).getLocation(), width*2,height*2,width,height);}else if (stuList.get(3).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_3, stuList.get(3).getLocation(), width*3,height*3,width,height);}if (stuList.get(4).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_4, stuList.get(4).getLocation(), width,height,width,height);}else if (stuList.get(4).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_4, stuList.get(4).getLocation(), width,height*2,width,height);}else if (stuList.get(4).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_4, stuList.get(4).getLocation(), width*2,height,width,height);}else if (stuList.get(4).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_4, stuList.get(4).getLocation(), width*2,height*2,width,height);}else if (stuList.get(4).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_4, stuList.get(4).getLocation(), width*3,height*3,width,height);}if (stuList.get(5).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_5, stuList.get(5).getLocation(), width,height,width,height);}else if (stuList.get(5).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_5, stuList.get(5).getLocation(), width,height*2,width,height);}else if (stuList.get(5).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_5, stuList.get(5).getLocation(), width*2,height,width,height);}else if (stuList.get(5).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_5, stuList.get(5).getLocation(), width*2,height*2,width,height);}else if (stuList.get(5).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_5, stuList.get(5).getLocation(), width*3,height*3,width,height);}if (stuList.get(6).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_6, stuList.get(6).getLocation(), width,height,width,height);}else if (stuList.get(6).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_6, stuList.get(6).getLocation(), width,height*2,width,height);}else if (stuList.get(6).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_6, stuList.get(6).getLocation(), width*2,height,width,height);}else if (stuList.get(6).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_6, stuList.get(6).getLocation(), width*2,height*2,width,height);}else if (stuList.get(6).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_6, stuList.get(6).getLocation(), width*3,height*3,width,height);}if (stuList.get(7).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_7, stuList.get(7).getLocation(), width,height,width,height);}else if (stuList.get(7).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_7, stuList.get(7).getLocation(), width,height*2,width,height);}else if (stuList.get(7).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_7, stuList.get(7).getLocation(), width*2,height,width,height);}else if (stuList.get(7).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_7, stuList.get(7).getLocation(), width*2,height*2,width,height);}else if (stuList.get(7).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_7, stuList.get(7).getLocation(), width*3,height*3,width,height);}if (stuList.get(8).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_8, stuList.get(8).getLocation(), width,height,width,height);}else if (stuList.get(8).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_8, stuList.get(8).getLocation(), width,height*2,width,height);}else if (stuList.get(8).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_8, stuList.get(8).getLocation(), width*2,height,width,height);}else if (stuList.get(8).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_8, stuList.get(8).getLocation(), width*2,height*2,width,height);}else if (stuList.get(8).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_8, stuList.get(8).getLocation(), width*3,height*3,width,height);}if (stuList.get(9).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_9, stuList.get(9).getLocation(), width,height,width,height);}else if (stuList.get(9).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_9, stuList.get(9).getLocation(), width,height*2,width,height);}else if (stuList.get(9).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_9, stuList.get(9).getLocation(), width*2,height,width,height);}else if (stuList.get(9).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_9, stuList.get(9).getLocation(), width*2,height*2,width,height);}else if (stuList.get(9).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_9, stuList.get(9).getLocation(), width*3,height*3,width,height);}if (stuList.get(10).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_10, stuList.get(10).getLocation(), width,height,width,height);}else if (stuList.get(10).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_10, stuList.get(10).getLocation(), width,height*2,width,height);}else if (stuList.get(10).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_10, stuList.get(10).getLocation(), width*2,height,width,height);}else if (stuList.get(10).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_10, stuList.get(10).getLocation(), width*2,height*2,width,height);}else if (stuList.get(10).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_10, stuList.get(10).getLocation(), width*3,height*3,width,height);}if (stuList.get(11).getSize()==11){AdaptScreenUtils.getScreenHeight5(card_11, stuList.get(11).getLocation(), width,height,width,height);}else if (stuList.get(11).getSize()==12){AdaptScreenUtils.getScreenHeight5(card_11, stuList.get(11).getLocation(), width,height*2,width,height);}else if (stuList.get(11).getSize()==21){AdaptScreenUtils.getScreenHeight5(card_11, stuList.get(11).getLocation(), width*2,height,width,height);}else if (stuList.get(11).getSize()==22){AdaptScreenUtils.getScreenHeight5(card_11, stuList.get(11).getLocation(), width*2,height*2,width,height);}else if (stuList.get(11).getSize()==33){AdaptScreenUtils.getScreenHeight5(card_11, stuList.get(11).getLocation(), width*3,height*3,width,height);}/** 必须想办法 查看一下控件的大小才行呢* */ViewTreeObserver vto3 = card_1.getViewTreeObserver();vto3.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {@Overridepublic void onGlobalLayout() {int width = card_1.getWidth();int height = card_1.getHeight();// 在获取到宽高之后要及时移除监听器,避免重复调用Log.e("TAG","card_1:AutoCardActivity_data:"+width+"==="+height);card_1.getViewTreeObserver().removeOnGlobalLayoutListener(this);}});}return false;}});@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);card_0 = findViewById(R.id.auto_card_0);card_1 = findViewById(R.id.auto_card_1);card_2 = findViewById(R.id.auto_card_2);card_3 = findViewById(R.id.auto_card_3);card_4 = findViewById(R.id.auto_card_4);card_5 = findViewById(R.id.auto_card_5);card_6 = findViewById(R.id.auto_card_6);card_7 = findViewById(R.id.auto_card_7);card_8 = findViewById(R.id.auto_card_8);card_9 = findViewById(R.id.auto_card_9);card_10 = findViewById(R.id.auto_card_10);card_11 = findViewById(R.id.auto_card_11);stuList = new ArrayList<>();loadJsonFromAssests();}public void loadJsonFromAssests() {String json = null;try {InputStream inputStream = getAssets().open("stu0.json");int size = inputStream.available();byte[] buffer = new byte[size];inputStream.read(buffer);inputStream.close();json = new String(buffer, "UTF-8");} catch (IOException ex) {ex.printStackTrace();}Log.i("TAG", "loadJsonFromAssests:" + json.toString());Message msg = new Message();msg.what = 100;msg.obj = json.toString();mHandler.sendMessage(msg);}}

end

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/12421.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

129.哈希表:有效的字母异位词(力扣)

242. 有效的字母异位词 - 力扣&#xff08;LeetCode&#xff09; 题目描述 代码解决以及思路 这个方法的时间复杂度为O(N)&#xff0c;其中N是字符串的长度&#xff0c;空间复杂度为O(1)&#xff08;因为辅助数组的大小是固定的26&#xff09;。 class Solution { public:bo…

初识C++ · string的使用(2)

目录 1 Modifiers部分 1.1 assign的使用 1.2 insert的使用 1.3 erase的使用 1.4 replace的使用 2 capacity部分 2.1 max_size的使用 2.2 capacity的使用 2.3 reserve的使用 2.4 shrink_to_fit简介 2.5 resize的使用 2.6 clear的使用 3 String operations部分 3.1 …

[数据结构1.0]快速排序

最近学习了快速排序&#xff0c;鼠鼠俺来做笔记了&#xff01; 本篇博客用排升序为例介绍快速排序&#xff01; 1.快速排序 快速排序是Hoare于1962年提出的一种二叉树结构的交换排序方法&#xff0c;其基本思想为&#xff1a;任取待排序元素序列中的某元素作为基准值&#x…

Java面试八股之一个char类型变量能不能存储一个中文字符

Java中一个char类型变量能不能存储一个中文字符&#xff1f;为什么&#xff1f; Java中一个char类型变量可以存储一个中文字符。原因如下&#xff1a; Unicode编码支持&#xff1a;Java语言采用Unicode字符集作为其内建字符编码方式。Unicode是一种广泛接受的字符编码标准&am…

两小时看完花书(深度学习入门篇)

1.深度学习花书前言 机器学习早期的时候十分依赖于已有的知识库和人为的逻辑规则&#xff0c;需要人们花大量的时间去制定合理的逻辑判定&#xff0c;可以说是有多少人工&#xff0c;就有多少智能。后来逐渐发展出一些简单的机器学习方法例如logistic regression、naive bayes等…

什么是CCRC?做什么用的?

CCRC&#xff08;中国网络安全审查认证和市场监管大数据中心&#xff09;原名为中国网络安全审查技术与认证中心&#xff0c;也被称为中国信息安全认证中心&#xff08;ISCCC&#xff09;。 该中心是经中央机构编制委员会办公室批准成立的&#xff0c;其主要职责是依据国家法律…

超级简单的地图操作工具开发可疑应急,地图画点,画线,画区域,获取地图经纬度等

使用echars的地图画点,画线,画区域,获取地图经纬度等 解压密码:10086007 地图也是用临时的bmap.js和china.js纯离线二选一 一共就这么多文件 画点,画线,画区域 点击地图获取经纬度-打印到控制台,这样就能渲染航迹,多变形,结合其他算法算圆等等操作 下载资源:https://download…

代码随想录训练营Day28:贪心算法06

1.738单调递增的数字 贪心策略&#xff1a;如果strNum[i]<strNum[i-1]那么strNum[i] 9,strNum[i-1]--;//比如87对应的最大的单调递增的就是79. 具体实现&#xff1a; 对于遇到小于的情况&#xff1a;如果strNum[i]<strNum[i-1]那么strNum[i] 9,strNum[i-1]--;遍历顺…

linux phpstudy 重启命令

[rootLinuxWeb phpstudy]# ./system/phpstudyctl restart 查看命令 1) phpstudy -start 启动小皮面板 2) phpstudy -stop 停止小皮面板 3) phpstudy -restart 重启小皮面板 4) phpstudy -status 查询面板状态 5) phpstudy -in…

OFDM802.11a的FPGA实现(十五)短训练序列:STS(含Matlab和verilog代码)

原文链接&#xff08;相关文章合集&#xff09;&#xff1a;OFDM 802.11a的xilinx FPGA实现 1.前言 在之前已经完成了data域数据的处理&#xff0c;在构建整个802.11a OFDM数据帧的时候&#xff0c;还剩下前导码和signal域的数据帧&#xff0c;这两部分的内容。 PLCP的前导部分…

Nodejs笔记2

模块化 模块化初体验 模块暴露数据 导入模块 fs 写绝对路径 require写相对路径不会受到影响 ./../不能省略 js 和json文件后缀可以省略 如果存在 命名相同的js和json文件&#xff0c;优先导入js文件 导入文件夹时的情况 require导入模块的基本流程 commonJS模块…

其它高阶数据结构①_并查集(概念+代码+两道OJ)

目录 1. 并查集的概念 2. 并查集的实现 3. 并查集的应用 3.1 力扣LCR 116. 省份数量 解析代码1 解析代码2 3.2 力扣990. 等式方程的可满足性 解析代码 本篇完。 写在前面&#xff1a; 此高阶数据结构系列&#xff0c;虽然放在⑤数据结构与算法专栏&#xff0c;但还是作…

【数据可视化01】matplotlib实例介绍4之六边形分箱图

目录 一、引言二、实例介绍 一、引言 hexbin是一个二维直方图&#xff0c;其中箱子是六边形&#xff0c;颜色表示每个箱子内的数据点数。 二、实例介绍 import matplotlib.pyplot as plt import numpy as np# Fixing random state for reproducibility np.random.seed(19680…

服务器利用率的神器脚本

在服务器管理的过程中&#xff0c;了解服务器的各项性能指标是至关重要的。无论是CPU的负载情况&#xff0c;内存使用情况&#xff0c;还是硬盘的存储空间以及TCP连接状态&#xff0c;这些都是我们判断服务器健康状态和性能的重要依据。然而&#xff0c;手动一项项去检查这些指…

【MySQL】Mysql——安装指南(Linux)

MySQL8.0.26-Linux版安装 1. 准备一台Linux服务器 云服务器或者虚拟机都可以; Linux的版本为 CentOS7; 2. 下载Linux版MySQL安装包 3. 上传MySQL安装包 4. 创建目录,并解压 mkdir mysqltar -xvf mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar -C mysql5. 安装mysql的安装包 …

pip镜像源

1.1 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple 1.2 阿里云 https://mirrors.aliyun.com/pypi/simple/ 1.3 网易 https://mirrors.163.com/pypi/simple/ 1.4 豆瓣 https://pypi.douban.com/simple/ 1.5 百度云 https://mirror.baidu.com/pypi/simple/ 1.6 中科大 ht…

RAG 面向 LLM: 基于检索增强的大语言模型调研

摘要 作为 AI 领域最先进的技术之一,检索增强生成(RAG)技术可以提供可靠和最新的外部知识,为众多任务提供巨大的便利。特别是在 AI 生成内容(AIGC)时代,RAG 中检索强大的提供额外知识的能力使得检索增强生成能够辅助现有生成式 AI 生产高质量输出。最近,大语言模型(LLM)在语言…

Zoho CRM企业成长的智能引擎,智能化销售自动化

数字化时代&#xff0c;客户体验已成为企业竞争的核心要素。卓豪Zoho CRM&#xff0c;作为全球领先的SaaS云端客户关系管理平台&#xff0c;正引领着一场企业运营模式的变革&#xff0c;助力超过25万家企业跨越180多个国家&#xff0c;实现客户互动与业务增长的无缝对接。让我们…

广汽原车控制系统CAN协议控制汽车基本信息获取及数据应用

在现代汽车工业的迅速发展中&#xff0c;车辆控制系统的智能化和网络化已成为提升汽车性能的关键。广汽作为中国汽车行业的佼佼者&#xff0c;其在原车通信网络方面也取得了显著的成就。特别是广汽原车CAN&#xff08;Controller Area Network&#xff09;协议的应用&#xff0…

短视频最后的慢动作怎么做:成都鼎茂宏升文化传媒公司

短视频最后的慢动作怎么做&#xff1a;技巧与创意实践指南 在短视频创作的浩瀚宇宙中&#xff0c;慢动作特效如同一颗璀璨的星辰&#xff0c;为作品增添无限魅力与情感深度。它不仅能够放大细节之美&#xff0c;还能延长关键瞬间&#xff0c;引发观众强烈的情感共鸣。短视频最…