首页 > 其他分享 >直播平台搭建,自定义View实现loading动画加载

直播平台搭建,自定义View实现loading动画加载

时间:2023-10-13 14:27:20浏览次数:44  
标签:loading 自定义 private context View view

直播平台搭建,自定义View实现loading动画加载

先自定义一个View,继承自LinearLayout,在Layout中,添加布局控件

 


/**
 * Created by xiedong on 2017/3/7.
 */
 
public class Loading_view extends LinearLayout {
    private Context mContext;
    private RelativeLayout loading_content;
    private ImageView img;
    private TextView loadingText;
 
    private AnimationDrawable animationDrawable;
 
    public Loading_view(Context context) {
        super(context);
        mContext = context;
        setupView();
    }
 
    public Loading_view(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        setupView();
    }
 
    public Loading_view(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        setupView();
    }
 
    private void setupView() {
//    View view= LayoutInflater.from(mContext).inflate(R.layout.loading_view_layout,this);     //一定要把布局添加进容器,不能为null
 
        View.inflate(mContext, R.layout.loading_view_layout, this);
 
        loading_content = (RelativeLayout) findViewById(R.id.loading_content);
        img = (ImageView) findViewById(R.id.img);
        loadingText = (TextView) findViewById(R.id.text);
 
        img.setImageResource(R.drawable.anim_loading);
        animationDrawable = ((AnimationDrawable) img.getDrawable());
        animationDrawable.start();
    }
 
    public void setMessage(String msg) {
        loadingText.setText(msg);
    }
}

 

自定义View的布局文件:

 


<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#90000000" android:gravity="center"> <RelativeLayout android:id="@+id/loading_content" android:layout_width="150dp" android:layout_height="120dp" android:background="#40ffffff"> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@mipmap/ic_launcher" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/img" android:layout_centerHorizontal="true" android:text="加载中..." /> </RelativeLayout> </LinearLayout> 
 

 

 

这里使用AnimationDrawable的方式来实现动画效果,AnimationDrawable的list文件如下:

 


 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/loading1" android:duration="100" /> <item android:drawable="@drawable/loading2" android:duration="100" /> <item android:drawable="@drawable/loading3" android:duration="100" /> <item android:drawable="@drawable/loading10" android:duration="100" /> </animation-list>
 
 
 

 

自定义View部分的工作完成之后,接下来就是如何在项目中具体运用。在相应的布局中使用的时候,一定要记得把此布局文件add进ViewGroup中,因为该自定义的View跟调用他的View是独立的两个View,没有完成add的话,loading布局可能不会显示出来。

 

private Loading_view loading_view; loading_view = new Loading_view(this); //实例化自定义VIew loading_view.setMessage("loading文字提示内容...."); //添加当前自定义View进主布局文件 addContentView(loading_view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));  

 

以上就是直播平台搭建,自定义View实现loading动画加载, 更多内容欢迎关注之后的文章

 

标签:loading,自定义,private,context,View,view
From: https://www.cnblogs.com/yunbaomengnan/p/17761962.html

相关文章

  • FlashDuty Changelog 2023-09-21 | 自定义字段和开发者中心
    FlashDuty:一站式告警响应平台,前往此地址免费体验!自定义字段FlashDuty已支持接入大部分常见的告警系统,我们将推送内容中的大部分信息放到了Lables进行展示。尽管如此,我们用户还是会有一些扩展或定制性的需求,比如人工标记一个故障是否为误报。因此我们提供了自定义字段功能,......
  • 无涯教程-DBUtils - 自定义行处理器
    如果数据库表中的列名和Javabean对象名不一样,那么无涯教程可以使用自定义的BasicRowProcessor对象来映射它们。请参见下面的示例。以下是Employee.java的内容。publicclassEmployee{privateintid;privateintage;privateStringfirst;privateString......
  • [iOS开发教程-1]Hello UITableView!
    http://www.iphonedevcentral.com/hello-uitableview/ HelloUITableView!Ok,let’sstartwithsomethingreallysimple.We’llbecreatinganapptokeeptrackofyourDVDlibrary. Theappwillhaveatableview,adetailviewandsomebasicnavigationalcompo......
  • Linux系统下配置Nginx使部分URL使用多套自定义的PHP-FPM配置
    Nginx修改演示:vim/usr/local/nginx/conf/vhost/example.comserver{ listen80; server_name192.168.1.180; location/{ root/Code/project/public; indexindex.phpindex.html; include/usr/local/nginx/conf/rewrite/laravel.conf;location~\.......
  • java框架中的controller层、dao层、domain层、service层、view层【转】
      1.Controller层:接口层,用户访问请求时对接。  Controller层负责具体的业务模块流程的控制,在此层里面要调用Serice层的接口来控制业务流程,控制的配置也同样是在Spring的配置文件里面进行,针对具体的业务流程,会有不同的控制器,我们具体的设计过程中可以将流程进行抽象归......
  • 直播平台源代码,自定义设置 View 四个角的圆角 以及边框的设置
    直播平台源代码,自定义设置View四个角的圆角以及边框的设置使用贝塞尔曲线 typedefNS_OPTIONS(NSUInteger,UIRectCorner){  UIRectCornerTopLeft   =1<<0,  UIRectCornerTopRight  =1<<1,  UIRectCornerBottomLeft =1<<2,  UIRectCo......
  • 微信小程序scroll-view
    <!--纵向滚动--><scroll-viewclass="myScroll"scroll-y><viewclass="row">1</view><viewclass="row">2</view><viewclass="row">3</view><viewclass="row&q......
  • Android 设置任意View的背景为圆形或圆角
    原文地址:Android设置任意View的背景为圆形或圆角-Stars-One的杂货小窝我的需求主要还是在SurfaceView需要设置为圆形背景,在网上找了下,发现一个可行方法,做个记录importandroid.graphics.Outline;importandroid.graphics.Rect;importandroid.view.View;importandr......
  • ADO.NET读取MySQL数据库的三种方式:DataReader、DataSet、DataView
    https://blog.csdn.net/lilongsy/article/details/127351421ADO.NET读取MySQL数据库有多种方式:DataReader、DataSet、DataView。Command对象的ExecuteScalar方法查询数据库获取某个单个值,但是如果获取多行、多列可以用ExcecuteReader,ExcecuteReader返回一个DataReader的数据流对......
  • Vue自定义指令实现复制功能
    importVuefrom'vue'importstorefrom'../store'functioncopyMethod(value){lettext=''switch(typeofvalue){case'number':text=value.toString()breakcase'object':text=JSON......