android 自定义脚本,Android实现自定义加载框的代码示例

App在与服务器进行网络交互的时候,需要有一个提示的加载框,如图:

86ddea360ec40006e826dca153f82066.png

此时我们可以自定义一个加载中的对话框,代码如下:

public class LoadingDialog extends Dialog {

private static final int CHANGE_TITLE_WHAT = 1;

private static final int CHNAGE_TITLE_DELAYMILLIS = 300;

private static final int MAX_SUFFIX_NUMBER = 3;

private static final char SUFFIX = '.';

private ImageView iv_route;

private TextView detail_tv;

private TextView tv_point;

private RotateAnimation mAnim;

private Handler handler = new Handler() {

private int num = 0;

public void handleMessage(android.os.Message msg) {

if (msg.what == CHANGE_TITLE_WHAT) {

StringBuilder builder = new StringBuilder();

if (num >= MAX_SUFFIX_NUMBER) {

num = 0;

}

num++;

for (int i = 0; i < num; i++) {

builder.append(SUFFIX);

}

tv_point.setText(builder.toString());

if (isShowing()) {

handler.sendEmptyMessageDelayed(CHANGE_TITLE_WHAT, CHNAGE_TITLE_DELAYMILLIS);

}

else {

num = 0;

}

}

};

};

public LoadingDialog(Context context) {

super(context, R.style.Dialog_bocop);

init();

}

public LoadingDialog(Context context, boolean isTrans) {

super(context, isTrans ? R.style.Loading_Dialog_trans : R.style.Dialog_bocop);

init();

}

private void init() {

setContentView(R.layout.common_dialog_loading_layout);

iv_route = (ImageView) findViewById(R.id.iv_route);

detail_tv = (TextView) findViewById(R.id.detail_tv);

tv_point = (TextView) findViewById(R.id.tv_point);

initAnim();

getWindow().setWindowAnimations(R.anim.alpha_in);

}

private void initAnim() {

// mAnim = new RotateAnimation(360, 0, Animation.RESTART, 0.5f, Animation.RESTART, 0.5f);

mAnim = new RotateAnimation(0, 360, Animation.RESTART, 0.5f, Animation.RESTART, 0.5f);

mAnim.setDuration(2000);

mAnim.setRepeatCount(Animation.INFINITE);

mAnim.setRepeatMode(Animation.RESTART);

mAnim.setStartTime(Animation.START_ON_FIRST_FRAME);

}

@Override

public void show() {//在要用到的地方调用这个方法

iv_route.startAnimation(mAnim);

handler.sendEmptyMessage(CHANGE_TITLE_WHAT);

super.show();

}

@Override

public void dismiss() {

mAnim.cancel();

super.dismiss();

}

@Override

public void setTitle(CharSequence title) {

if (TextUtils.isEmpty(title)) {

detail_tv.setText("正在加载");

}

else {

detail_tv.setText(title);

}

}

@Override

public void setTitle(int titleId) {

setTitle(getContext().getString(titleId));

}

public static void dismissDialog(LoadingDialog loadingDialog) {

if (null == loadingDialog) { return; }

loadingDialog.dismiss();

}

}

-------------对应的布局如下------------------

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="160dp"

android:layout_height="160dp"

android:layout_gravity="center"

android:background="@drawable/common_show_dialog"

android:orientation="vertical" >

android:layout_width="fill_parent"

android:layout_height="0dp"

android:layout_weight="3"

android:paddingTop="22dp"

android:gravity="center" >

android:id="@+id/iv_route"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:background="@drawable/dialog_bocop_loading_rotate_anim_img" />

android:layout_width="fill_parent"

android:layout_height="0dp"

android:layout_marginBottom="15dp"

android:layout_marginLeft="10dp"

android:layout_marginRight="10dp"

android:layout_weight="1"

android:gravity="center_horizontal" >

android:id="@+id/detail_tv"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toLeftOf="@+id/tv_point"

android:ellipsize="marquee"

android:gravity="center"

android:singleLine="true"

android:text="正在加载..."

android:textColor="#ffffff"

android:textSize="20sp" />

android:id="@+id/tv_point"

android:layout_width="20dp"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:text="..."

android:textColor="#ffffff"

android:textSize="20sp" />

比如在Activity中要实现加载对话框调用 :

LoadingDialog loadingDialog ;

if (null == loadingDialog) {

loadingDialog = new LoadingDialog(aty);

loadingDialog.setOnCancelListener(this);

}

loadingDialog.setTitle(“数据加载中”);

if (!loadingDialog.isShowing()) loadingDialog.show();

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python快手自定义评论脚本代码可以通过使用Selenium库来实现。 首先,我们需要安装Selenium库。可以通过运行以下命令安装Selenium: ``` pip install selenium ``` 接下来,我们需要下载并配置驱动程序,以便Selenium能够与浏览器进行通信。驱动程序的选择取决于你使用的浏览器。例如,如果你使用的是Chrome浏览器,你需要下载ChromeDriver,并将其添加到系统路径中。 下面是一个示例脚本,用于在快手视频中自动评论: ```python from selenium import webdriver from selenium.webdriver.common.keys import Keys from time import sleep # 设置浏览器驱动程序路径 driver_path = "path_to_chromedriver" # 创建浏览器对象 driver = webdriver.Chrome(driver_path) # 打开快手网页 driver.get("https://www.kuaishou.com") # 等待页面加载完成 sleep(3) # 根据需要登录快手账号 # ... # 进入指定的视频页面 video_url = "https://www.kuaishou.com/video/{video_id}" driver.get(video_url) # 等待视频页面加载完成 sleep(3) # 在评论中输入自定义评论内容 comment_input = driver.find_element_by_xpath("//input[@id='comment-textarea']") comment_input.send_keys("自定义评论内容") # 发布评论 comment_input.send_keys(Keys.RETURN) # 关闭浏览器 driver.quit() ``` 在上述代码中,你需要将`path_to_chromedriver`替换为你自己ChromeDriver的实际路径,并将`{video_id}`替换为你想要评论的视频的ID。 该脚本会打开指定的快手视频页面,并自动在评论中输入自定义评论内容,然后发布评论。 需要注意的是,使用自动化脚本可能违反快手的使用条款,因此在使用该脚本之前,请确保你已经阅读并理解了快手的条款和条件,并获得了适当的授权。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值