小编Leo*_*Leo的帖子

无法删除ViewPropertyAnimator的侦听器

当我跑我的自定义视图里面的代码,onAnimationStartonAnimationEnd保持被重复调用.这不是很奇怪吗?作为Android程序员,我预计它们只会被分别调用一次.

    final ViewPropertyAnimator animator = animate().setDuration(1000).alpha(0.0f);
    animator.setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            Utils.log("----------------start");
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            Utils.log("--------- end");
        }
    }).start();
Run Code Online (Sandbox Code Playgroud)

但后来我尝试通过在onAnimationEndViewPropertyAnimators 调用时删除监听器来解决问题,setListener(null)但是尽管在文档中写了什么,它仍然无法工作:

public ViewPropertyAnimator setListener (Animator.AnimatorListener listener)

Added in API level 12
Sets a listener for events in the underlying Animators that run the property animations.

Parameters
listener    The listener to be called with AnimatorListener events. A value of null removes any existing …
Run Code Online (Sandbox Code Playgroud)

android viewpropertyanimator

7
推荐指数
1
解决办法
3032
查看次数

如何在Java中用\n替换\\n

我有一个 string test="first \\n middle \\n last"

现在我想更换所有"\\n""\n"

我已经尝试了test.replaceAll("\\\\n", "\\n"),test.replaceAll("\\n", "\n")但他们不工作任何人都有解决方案?

谢谢!

java

3
推荐指数
1
解决办法
5649
查看次数

如何用BulletSpan创建一个空子弹段?

我想创建一个空的子弹段落,但它没有用.这是我的代码:

EditText contentET = (EditText) findViewById(R.id.content);
contentET.setText("abc\n123\n");
Spannable s = contentET.getText();
s.setSpan(new BulletSpan(), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
s.setSpan(new BulletSpan(), 4, 5, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
s.setSpan(new BulletSpan(), 7, 8, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
contentET.setText(s);
Run Code Online (Sandbox Code Playgroud)

当我运行上面的代码时,似乎这行不起作用

s.setSpan(new BulletSpan(), 7, 8, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
Run Code Online (Sandbox Code Playgroud)

相反,我在"123"之后看到了意想不到的空白区域.任何人都知道如何用BulletSpan创建一个空子弹段?谢谢!

android android-edittext spannable

3
推荐指数
1
解决办法
5825
查看次数

如何设置ExpandableListView的指示器图标的宽度和高度?

我已经使用选择器为我的ExpandableListView设置了指示器图标,但是我的折叠和展开图标被调整大小以匹配原始指示器图标的大小(比我的图标大).任何人都知道如何设置指标图标的大小(宽度和高度)?谢谢!

android expandablelistview

2
推荐指数
2
解决办法
6779
查看次数

使用Selector进行无限循环,即使客户端没有连接

我是Java NIO的新手,在阅读了一些教程之后,我尝试自己编写了一个简单的NIO服务器和客户端。我的服务器做的一件简单的事情就是从客户端侦听并打印到控制台,客户端仅连接到服务器并向其发送3条消息“ Hello”。问题是我的服务器监听了这3条消息,并能很好地处理这3条消息,之后应该将其阻止并继续监听,但是没有,没有阻止,它会无限循环地运行它。这是我的服务器和客户端:

服务器

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.util.Iterator;
import java.util.Set;

public class Server {
    public static void main(String args[]) throws Exception {
        // Create the server socket channel
        ServerSocketChannel server = ServerSocketChannel.open();
        // nonblocking I/O
        server.configureBlocking(false);
        // host-port 8000
        server.socket().bind(new InetSocketAddress(8000));
        System.out.println("Server actives at port 8000");
        // Create the selector
        Selector selector = Selector.open();
        // Recording server to selector (type OP_ACCEPT)
        server.register(selector, SelectionKey.OP_ACCEPT);

        while …
Run Code Online (Sandbox Code Playgroud)

java nio selector

2
推荐指数
1
解决办法
2872
查看次数

仅通过一个SocketChannel发送多条消息

阅读本教程后:http : //rox-xmlrpc.sourceforge.net/niotut/(这是关于编写非阻塞服务器和客户端的信息,我阅读了NIO部分,跳过了SSL部分),现在我正尝试重写自己的内容客户端,但是在尝试编辑客户端代码时遇到了问题。

首先,我想让您看到本教程的客户端代码,它包含2个文件:

但是我在main函数中编辑了NIOClient.java 来解释我的问题,如下所示:

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.SelectorProvider;
import java.util.*;

public class NIOClient implements Runnable {
// The host:port combination to connect to
private InetAddress hostAddress;
private int port;

// The selector we'll be monitoring
private Selector selector;

// The buffer into which we'll read data when it's available
private ByteBuffer readBuffer = ByteBuffer.allocate(8192);

// A list …
Run Code Online (Sandbox Code Playgroud)

java nio socketchannel

1
推荐指数
1
解决办法
7147
查看次数

如何在java中删除字符串"\ u001b [1m"

收到服务器的内容响应后,将内容打印到控制台,我意识到字符串"\ u001b [1m"]的存在,我认为这是我无法解析作为JSON对象的响应的原因.

我想删除字符串,任何解决方案?

java special-characters

0
推荐指数
1
解决办法
1806
查看次数