小编fde*_*hin的帖子

自定义搜索栏拇指在Lollipop API21上不透明

这是我的搜索:

<SeekBar
    android:id="@+id/seek1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:progressDrawable="@drawable/style_progressbar"
    android:thumb="@drawable/style_progressbar_circle"
    android:progress="20" />
Run Code Online (Sandbox Code Playgroud)

这是style_progressbar.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape android:shape="rectangle" >
            <corners android:radius="5dp" />
            <gradient
                android:angle="270"
                android:endColor="@color/gris_hint"
                android:startColor="@color/gris_hint" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape android:shape="rectangle" >
                <corners android:radius="5dp" />
                <gradient
                    android:angle="270"
                    android:endColor="@color/gris"
                    android:startColor="@color/gris" />
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape android:shape="rectangle" >
                <corners android:radius="5dp" />
                <gradient
                    android:angle="270"
                    android:endColor="@color/gris"
                    android:startColor="@color/gris" />
            </shape>
        </clip>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

这是style_progressbar_circle.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/red_scrubber_control_disabled_holo" android:state_enabled="false"/>
    <item android:drawable="@drawable/red_scrubber_control_pressed_holo" android:state_pressed="true"/>
    <item android:drawable="@drawable/red_scrubber_control_focused_holo" android:state_selected="true"/>
    <item …
Run Code Online (Sandbox Code Playgroud)

layout android android-seekbar android-5.0-lollipop

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

使水平回收者视图项的宽度为屏幕宽度的70%

我想创造这种效果

设计图像

我正在使用回收站视图,但我的问题是,每张卡都是100%的屏幕宽度,为70%.

这是每个项目的xml代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rowLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/scale_20dp">

    <LinearLayout
        android:id="@+id/button_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:id="@+id/currentYear"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="@drawable/paymentscreengrey"
                android:gravity="center"
                android:orientation="vertical"
                android:paddingLeft="35dp"
                android:paddingTop="@dimen/scale_50dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/scale_20dp"
                    android:text="****   ****   ****   5432"
                    android:textColor="@color/white"
                    android:textSize="@dimen/scale_20dp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="2345"
                    android:textColor="@color/white"
                    android:textSize="@dimen/scale_16dp" />
Run Code Online (Sandbox Code Playgroud)

xml android android-layout

16
推荐指数
4
解决办法
1万
查看次数

如何处理不适合任何语言数据结构的大整数

我正在尝试解决编程竞赛的初步问题以及我必须计算的两个问题,并打印一些非常大的整数(如100!,2 ^ 100).

我还需要一种快速计算这个大整数的能力的方法.

你可以为我建议一些算法或数据结构吗?(顺便说一下,我读过C接口和实现的'任意精度算术'部分,但它对pow()没有帮助)

编辑:我认为通过平方法和位移的取幂对功率起作用,但我还需要一种快速的方法来计算这个因子的阶乘.谢谢.

EDIT2:对于那些感兴趣的人;

找到包含长度为N的所有位串的最短位串长度(对不起我的英文,我举一个例子).N <= 10000

例如,包括长度为2(00,01,10,11)的所有比特串的最短比特串长度是5(11001).

我对这个问题的解决方案是2 ^ n + n - 1.(所以我应该计算2的幂,我想我会使用位移)

其他问题是,给定2个长度,找到你可以通过多少种方式达到长度N.例如,输入是10,2,3.那么你应该用2和3达到10(例如,2 + 3) 2 + 2 + 2 + 2,2 + 2 + 3 + 3,3 + 2 + 2 + 3,3 + 3 + 2 + 2 ......).1 <= N <2 ^ 63.我们将在mod 1000000007中计算anwser.

我的解决方案是,2x + 3y = N,所以x =(N - 3y)/ 2.对于从0到2*N/3的y,如果x是一个整数,那么我应该计算这个X和Y的广义置换,总计+ =(x + y)!/(x!*y!).

c algorithm biginteger arbitrary-precision data-structures

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

在QGraphicsScene中选择项目

我试图了解如何重新定义项目的选择和转换方式(一旦被选中)QGraphicsScene.例如,更改线条的长度,移动线条,通过移动其中一个点来更改多边形.

我创建了一个孩子QGraphicsView并且已经开始重载它mousePressEvent,但似乎选择和移动动作都被捕获了QGraphicsItem.我怎样才能覆盖它,因为它们受到保护而且从孩子身上看不到QGraphicsView

我可以想象我需要QGraphicsItem::mousePressEvent在a中重载myGraphicsItem,但那意味着我还必须重载以QGraphicsScene进行处理myGraphicsItem?如何移动场景中的选定项目位置?

有什么我可以看的例子吗?

我(显然)有点失落.

更新:根据反馈,我创建了一个QGraphicsItems如下的孩子:

class baseGraphicItem : public QGraphicsItem
{
public:
    explicit baseGraphicItem(QVector<QPoint> data, operationType shape, QObject * parent = 0);

signals:

public slots:

public:
    virtual QRectF boundingRect() const;
    virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
    QPainterPath shape() const;
    virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event );
    virtual void hoverLeaveEvent ( …
Run Code Online (Sandbox Code Playgroud)

qt selection qgraphicsitem

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

Robolectric:在我的案例中运行处理程序的looper

我有一个非常简单的类Handler,当它处理消息时它再次发送新消息:

public class MyRepeatTask{
  …
  public void startTask() {
    // send message with delay 5 sec
    handler.sendMessageDelayed(handler.obtainMessage(…), 5000);
  }

  Handler  handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            // I put a log for unit test
            System.out.println(“handling message …”);
            // send message with delay again
            handler.sendMessageDelayed(handler.obtainMessage(…), 5000);
        }
  }
}
Run Code Online (Sandbox Code Playgroud)

如上所示,当startTask()调用时,处理程序在5秒内开始发送消息.然后,在handleMessage()回调中,handler再次发送延迟5秒的消息.这样做的目的是反复做一些任务(比如System.out.println()).

我用Robolectric测试上面的类:

@RunWith(RobolectricTestRunner.class)
public class MyRepeatTaskTest {
  @Test
  public void testStartTask() {
    MyRepeatTask task = …
Run Code Online (Sandbox Code Playgroud)

java android unit-testing robolectric

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

在python中合并两个文件夹

我需要合并两个文件夹,

文件夹命名为 12345 和 12345_

我将如何合并两者?

我试过了,但我最终得到了“12345”。

for file in files:
    subFolder = os.path.join(destpath, file[:6])
    if not os.path.isdir(subFolder):
        os.makedirs(subFolder)
    shutil.copy(os.path.join(root, file), subFolder)
Run Code Online (Sandbox Code Playgroud)

python merge

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

scipy中拟合算法的区别

我有一个关于scipy中使用的拟合算法的问题.在我的程序中,我有一组x和y数据点,只有y个错误,并且想要适合一个函数

f(x) = (a[0] - a[1])/(1+np.exp(x-a[2])/a[3]) + a[1]
Run Code Online (Sandbox Code Playgroud)

它.

问题是我使用两个拟合的scipy拟合例程scipy.odr.ODR(使用最小二乘算法)和scipy.optimize,在参数上得到了非常高的错误,并且得到了拟合参数的不同值和误差.我举个例子:

适合scipy.odr.ODR,fit_type = 2

Beta: [ 11.96765963 68.98892582 100.20926023 0.60793377]
Beta Std Error: [ 4.67560801e-01 3.37133614e+00 8.06031988e+04 4.90014367e+04]
Beta Covariance: [[ 3.49790629e-02 1.14441187e-02 -1.92963671e+02 1.17312104e+02]
[ 1.14441187e-02 1.81859542e+00 -5.93424196e+03 3.60765567e+03]
[ -1.92963671e+02 -5.93424196e+03 1.03952883e+09 -6.31965068e+08]
[ 1.17312104e+02 3.60765567e+03 -6.31965068e+08 3.84193143e+08]]
Residual Variance: 6.24982731975
Inverse Condition #: 1.61472215874e-08
Reason(s) for Halting:
Sum of squares convergence
Run Code Online (Sandbox Code Playgroud)

然后适合scipy.optimize.leastsquares:

适合scipy.optimize.leastsq

beta: [ 11.9671859 68.98445306 99.43252045 1.32131099]
Beta Std Error: [0.195503 1.384838 34.891521 45.950556]
Beta Covariance: …
Run Code Online (Sandbox Code Playgroud)

python mathematical-optimization curve-fitting scipy

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

Android 中的椭圆渐变

您可以使用以下代码生成圆形渐变:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <gradient
        android:centerColor="#c1c1c1"
        android:endColor="#4f4f4f"
        android:gradientRadius="400"
        android:startColor="#c1c1c1"
        android:type="radial" >
    </gradient>
   
</shape>
Run Code Online (Sandbox Code Playgroud)

但是如何在 Android 中绘制椭圆渐变呢?即X和Y的半径不同?

xml android gradient view

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

如何在回调接受多个参数时实现函数的promisify

有没有办法在函数中使用多于两个参数的函数?一个例子是node的fs.read,其中回调的三个参数是err,bytes和data.data参数不会传递给then函数,因此这会记录undefined:

var fs = require('fs');
var Promise = require('bluebird');
var open = Promise.promisify(fs.open);
var read = Promise.promisify(fs.read);

open('test.txt', 'r')
  .then(function(fd) {
    var buffer = new Buffer(1024);
    read(fd, buffer, 0, buffer.length, null).then(function(bytes, data) {
      console.log(data);
    });
  });
Run Code Online (Sandbox Code Playgroud)

javascript promise bluebird

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

如何以编程方式检查“enabled_notification_listeners”?

我需要检查我的应用程序的服务在“通知访问”中是否已启用。

我正在使用这段代码来检查这一点。该代码在Nougat上运行良好,但在Marshmallow上崩溃。我怎样才能在棉花糖上做到这一点?

android.provider.Settings.Secure.getString(this.getContentResolver(), "enabled_notification_listeners").contains(getApplicationContext().getPackageName())
Run Code Online (Sandbox Code Playgroud)

这是LogCat 中的错误

12-06 15:28:02.905 4428-4428/com.inetsoho.app.SkyChat E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.inetsoho.app.SkyChat, PID: 4428
    java.lang.IllegalStateException: Could not execute method for android:onClick
        at android.view.View$DeclaredOnClickListener.onClick(View.java:4740)
        at android.view.View.performClick(View.java:5697)
        at android.view.View$PerformClick.run(View.java:22526)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:158)
        at android.app.ActivityThread.main(ActivityThread.java:7224)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at android.view.View$DeclaredOnClickListener.onClick(View.java:4735)
        at android.view.View.performClick(View.java:5697) 
        at android.view.View$PerformClick.run(View.java:22526) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:158) 
        at android.app.ActivityThread.main(ActivityThread.java:7224) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) …
Run Code Online (Sandbox Code Playgroud)

android android-notifications

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