• 【安卓学习之常见问题】自定义组件-刷新后跳到第一行


    █ 【安卓学习之常见问题】自定义组件-刷新后跳到第一行


    █ 系列文章目录

    提示:这里是收集了和文件分享有关的文章

    █ 文章目录


    █ 读前说明

    • 本文通过学习别人写demo,学习一些课件,参考一些博客,’学习相关知识,如果涉及侵权请告知
    • 本文只简单罗列相关的代码实现过程
    • 涉及到的逻辑以及说明也只是简单介绍,主要当做笔记,了解过程而已    

    █ 问题

    • 数据会不断从服务器读取更新数据,一共有10行seekbar,不是用listview,而是直接复制了10个

    在这里插入图片描述
    >>>>可以正常上下滚动,以下是xml布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:fadeScrollbars="false"
            android:scrollbars="vertical">
            <!--已开抢-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:paddingLeft="10dp"
                android:paddingRight="10dp">
    
                <!--1-->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:orientation="vertical"
                    android:paddingLeft="1dp"
                    android:paddingRight="1dp">
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="45dp"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">
    
                        <SeekBar
                            android:id="@+id/my_seekBar"
                            style="@style/MySeekBarStyle"
                            android:layout_width="0dp"
                            android:layout_gravity="center"
                            android:layout_weight="1"
                            android:max="2200"
                            android:minWidth="150dp"
                            android:progress="10" />
    
                        <TextView
                            android:id="@+id/my_text_view"
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:gravity="center_vertical"
                            android:maxWidth="100dp"
                            android:minWidth="30dp"
                            android:textColor="@color/text_white"
                            android:textSize="16sp" />
    
                    </LinearLayout>
    				<!--分割线-->
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="#4D000000" />
    
                </LinearLayout>
    
                <!--2-->
    			。。。。。。
                <!--10-->
            </LinearLayout>
        </androidx.core.widget.NestedScrollView>
    
    </LinearLayout>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 新版本,使用了TabLayout+ViewPager2,共有3个Fragment,每个里面都有10行 seekbar

    在这里插入图片描述

    >>>>可以正常上下滚动,以下是xml布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="5dp"
            app:tabBackground="@drawable/tab_background"
            app:tabIndicatorColor="@color/transparent"
            app:tabIndicatorHeight="0dp"
            app:tabMinWidth="100dp"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/blue"
            app:tabTextColor="@color/white" />
    
        <androidx.viewpager2.widget.ViewPager2
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    </LinearLayout>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    █ 使用过程

    • 文件路径的传输过程(数据有点出入,因为刚开始测试是这样,后面测试又没有这个问题)
    依赖库获取值方法结果
    -Filenew File()/storage/emulated/0/
    Android/data/com.bx.share/files/share/xxx.mp3
    androidx.core:
    core:1.5.0
    UriFileProvider.getUriForFile(this, authority, file)content://com.bx.share.fileprovider/external_files/
    Android/data/com.bx.share/files/share/xxx.mp3
    androidx.core:
    core:1.6.0
    UriFileProvider.getUriForFile(this, authority, file)content://com.bx.share.fileprovider/files_root/
    Android/data/com.bx.share/files/share/xxx.mp3
    • 代码实现:
    		File shareFile = new File(mDirName, mFileName);// /storage/emulated/0/Android/data/com.bx.share/files/
            Uri uri;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                // content://com.bx.share.fileprovider/external_files/Android/data/com.bx.share/files/share/xxx.mp3
                uri = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", shareFile);
            } else {
                uri = Uri.fromFile(shareFile);
            }
            Intent intent = getChooserIntent(uri);
            
            Intent pickIntent = new Intent();
            pickIntent.setAction(Intent.ACTION_PICK_ACTIVITY);
            pickIntent.putExtra(Intent.EXTRA_TITLE, "4.分享文件 Pick Activity");
            pickIntent.putExtra(Intent.EXTRA_INTENT, intent);
            startActivityForResult(pickIntent, RESULT_SHARE);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
        public Intent getChooserIntent(Uri uri) {
            Intent intent = new Intent(Intent.ACTION_SEND);// 共享文件,部分app需要手机联网
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 传递权限
            intent.putExtra(Intent.EXTRA_TEXT, "分享测试123");
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.setType("application/*");// 二进制文件 "application/octet-stream" "*/*"
            return intent;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    █ 正常使用

    • 代码:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:fadeScrollbars="false"
            android:scrollbars="vertical">
            <!--已开抢-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:paddingLeft="10dp"
                android:paddingRight="10dp">
    
                <!--1-->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:orientation="vertical"
                    android:paddingLeft="1dp"
                    android:paddingRight="1dp">
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="45dp"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">
    
                        <SeekBar
                            android:id="@+id/my_seekBar"
                            style="@style/MySeekBarStyle"
                            android:layout_width="0dp"
                            android:layout_gravity="center"
                            android:layout_weight="1"
                            android:max="2200"
                            android:minWidth="150dp"
                            android:progress="10" />
    
                        <TextView
                            android:id="@+id/my_text_view"
                            android:layout_width="100dp" <!--修改后的-->
                            android:layout_height="match_parent"
                             android:editable="false" <!--修改后的-->
                            android:gravity="center_vertical"
                            android:maxWidth="100dp"
                            android:minWidth="30dp"
                            android:textColor="@color/text_white"
                            android:textSize="16sp" />
    
                    </LinearLayout>
    				<!--分割线-->
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="#4D000000" />
    
                </LinearLayout>
    
                <!--2-->
    			。。。。。。
                <!--10-->
            </LinearLayout>
        </androidx.core.widget.NestedScrollView>
    
    </LinearLayout>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73

    █ 相关资料

    提示:这里是参考的相关文章

    1. Android SVG to VectorDrawable >>>>svg转Vector
    2. 2016-12-23 Android Vector详解_yw1688的专栏-CSDN博客_android vector

    █ 免责声明

    博主分享的所有文章内容,部分参考网上教程,引用大神高论,部分亲身实践,记下笔录,内容可能存在诸多不实之处,还望海涵,本内容仅供学习研究使用,切勿用于商业用途,若您是部分内容的作者,不喜欢此内容被分享出来,可联系博主说明相关情况通知删除,感谢您的理解与支持!

    转载请注明出处:
    https://blog.csdn.net/ljb568838953/article/details/110383353

  • 相关阅读:
    Vue框架学习笔记——v-bind数据单向绑定和v-model数据双向绑定
    bootstrap学习:自定义栅格系统
    opencv-图像梯度
    20款短视频自媒体必备工具,让你的运营效率翻倍
    驱动开发day4(实现通过字符设备驱动的分布实现编写LED驱动,实现设备文件的绑定)
    0019Java程序设计-SSM + MySQL 家庭医生预约平台
    MotoSimEG-VRC软件:安川机器人用户坐标系介绍与标定方法
    每日刷题记录 (九)
    LeetCode——1422.分割字符串的最大得分
    JAVA线程池
  • 原文地址:https://blog.csdn.net/ljb568838953/article/details/126629521