自制背数学公式APP源码分享+踩坑记录

一、简介

最近本人开发了一个背数学公式的APP,在此分享下源码和APP,需要的大佬自行下载即可,下载地址在下方。

用AndroidStudio开发的,长这个样子:

比较简陋,不过自我感觉比较方便,够用了。

相当于图片浏览器吧,公式图片需要自己准备,格式不限,图片比例差不多点都行,推荐png,占用空间小。

 

二、源码+APP下载链接

git:(等上传后会填写的)

csdn(首次下载0积分):https://download.csdn.net/download/BHSZZY/16551993

 

三、使用方法

1.安装APP启动后,需要获取存取权限;

2.程序会在根目录下创建zmath文件夹,创建1张样例图片;

3.可以自己将容易遗忘的公式整理成图片,放到zmath文件夹下,然后此APP会读取这个路径下的图片,展示出来。

4.如果哪里觉得不满意,打开源码自己改就可以了。

 

四、踩坑记录

1.ImageView标签拉伸图片的方法:(本人只用到了adjustViewBounds)

android:adjustViewBounds="true"<!--不保持长宽比(图片可能变形)-->
android:scaleType="fitXY"<!--贴合X边,贴合Y边-->

2.执行申请权限的方法时,会弹出申请权限框;但是就算用户不操作,程序也不会停止;其实是希望程序阻断、等用户同意/拒绝后再继续执行的,但是不行。

因此单独写了一个申请权限的页面和按钮。

3.页面元素布局方法,可以决定这个元素在哪个元素的上面/下面等;把宽/高设置为0dp,有时可以实现元素居中与拉伸效果:

android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/jump"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nowAndSize"

4.获取文件夹下子文件的方法:先new一个File,使用文件夹的url;然后使用listFiles()方法

5.文件按照文件名排序的方法:

 public static File[] orderByName(File[] files) {
        List fileList = Arrays.asList(files);
        Collections.sort(fileList, new Comparator<File>() {
            @Override
            public int compare(File o1, File o2) {
                if (o1.isDirectory() && o2.isFile())
                    return -1;
                if (o1.isFile() && o2.isDirectory())
                    return 1;
                return o1.getName().compareTo(o2.getName());
            }
        });
        return (File[]) fileList.toArray();
}

6.将drawable中的图片保存到手机中的方法:

Drawable drawable = this.getResources().getDrawable(R.drawable.example);
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
File exampleFile = new File(Environment.getExternalStorageDirectory()+"/abc/", "example.png");
saveBitmap(bitmap, exampleFile, Bitmap.CompressFormat.PNG);


//这个是saveBitmap方法
public void saveBitmap(Bitmap bitmap, File file, Bitmap.CompressFormat format) {
        FileOutputStream out = null;
        try{
            // 打开指定文件输出流
            out = new FileOutputStream(file);
            // 将位图输出到指定文件
            bitmap.compress(format, 100,
                    out);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
}

7.修改ImageView的src后,要执行invalidate()方法:

ImageView img = (ImageView) findViewById(R.id.imageView);
img.setImageURI(Uri.fromFile(new File("/0/abc/example.png")));
img.invalidate();

8.强制某个页面竖屏的方法(否则屏幕旋转时会导致页面重新加载,处理这个更麻烦)

在AndroidManifest.xml中的activity标签中增加:android:screenOrientation="portrait"

强制横屏是android:screenOrientation=”landscape” 

<activity android:name=".MainActivity"
            android:screenOrientation="portrait">
        </activity>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

追逐梦想永不停

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值