小编Che*_*eng的帖子

使用TranslateAnimation后无法完全查看视图

我曾经使用TranslateAnimation过并在视图中上下滑动.

但是,我意识到,即使在我向下滑动视图并使用View.GONE其可见性后,视图仍然能够接收触摸事件.

您可以通过单击按钮使橙色视图从屏幕底部消失来产生相同的问题.然后,当您单击屏幕底部时,您将意识到仍然会触发自定义视图的触摸事件.

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        int color = getResources().getColor(android.R.color.holo_orange_light);
        // construct the RelativeLayout
        final RelativeLayout customView = new RelativeLayout(this) {
            @Override
            public boolean onTouchEvent(MotionEvent event) {
                this.setPressed(true);
                Log.i("CHEOK", "OH NO! TOUCH!!!!");
                return super.onTouchEvent(event);
            }
        };
        customView.setBackgroundColor(color);

        final FrameLayout frameLayout = (FrameLayout)this.findViewById(R.id.frameLayout); 
        frameLayout.addView(customView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 100, Gravity.BOTTOM));
        customView.setVisibility(View.GONE);


        Button button = (Button)this.findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (customView.getVisibility() != View.VISIBLE) …
Run Code Online (Sandbox Code Playgroud)

android

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

使用0 size数组作为List.toArray <T []>的参数

我想知道,这是一种将列表转换为数组的推荐方法,因为这两种方法似乎都运行正常.

在Java中将'ArrayList <String>转换为'String []',我看到的new String[list.size()]方式是推荐的,但我不确定为什么.

list.toArray(new String[0]);
Run Code Online (Sandbox Code Playgroud)
list.toArray(new String[list.size()]);
Run Code Online (Sandbox Code Playgroud)

java

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

9补丁图像中定义的内容区域不适用于自定义视图

目前,我有一个自定义视图BarChart.我希望它有一些红色阴影效果.我正在使用九种补丁图像技术来实现这一目标.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:minHeight="240dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/card_background_red"
    android:orientation="vertical"
    android:padding="0dp" >

    <org.yccheok.jstock.gui.charting.BarChart
        android:id="@+id/bar_chart"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在我的自定义视图中,有一行代码,我将在视图的结尾处绘制字符串.

// Drawing string at end-y of BarChart custom view.
canvas.drawText("2007", x0, getHeight(), textPaint); 
canvas.drawText("2008", x1, getHeight(), textPaint);
Run Code Online (Sandbox Code Playgroud)

我避免了我的自定义视图"触摸"任何红色阴影,我定义了9个补丁的内容区域,因此它不会触及红色阴影.

如您所见,内容区域几乎远离红色阴影.

在此输入图像描述

我认为我的绘制文本永远不会触及红色阴影区域,因为我限制了我的内容区域(整个自定义视图?)远离红色阴影区域.但是,它不起作用.

在此输入图像描述

我对9补丁图像的内容区域有错误的期望吗?我认为Linear Layout的"内容"是我的自定义视图BarChart.因此,BarChart不应该在9补丁图像中触摸特定的红色阴影.(http://www.shubhayu.com/android/9-patch-image-designers-vs-developers)

android

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

单线程池 - ExecutorService或Handler + HandlerThread

传统上,当我需要单个线程池时,我会使用

ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(...
Run Code Online (Sandbox Code Playgroud)

但是,在查看Weather List Widget时,我意识到我们可以使用Handler+ HandlerThread来实现类似的目标

HandlerThread sWorkerThread = new HandlerThread("WeatherWidgetProvider-worker");
sWorkerThread.start();
Handler sWorkerQueue = new Handler(sWorkerThread.getLooper());
sWorkerQueue.post(...
Run Code Online (Sandbox Code Playgroud)

我想知道,我应该考虑什么,以便在他们中间做出正确的选择?

multithreading android

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

onReceive将始终收到最后一个appWidgetId,甚至正在按下不同的实例窗口小部件

我有以下代码.我试图在我的主屏幕上放置2个小部件实例.

这是在放置2个小部件实例后打印的日志.

onUpdate START
onUpdate 170
onUpdate START
onUpdate 171
Run Code Online (Sandbox Code Playgroud)

当我点击第一个小部件,然后点击第二个小部件时,我预计将分别打印170和171.但是,这就是我得到的.

onReceive 171  <-- I'm expecting 170 to be printed.
onReceive 171
Run Code Online (Sandbox Code Playgroud)

我的代码有什么问题吗?或者,我的期望错了?

public class MyAppWidgetProvider extends AppWidgetProvider {    
    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        Log.i("CHEOK", "onUpdate START");

        for (int appWidgetId : appWidgetIds) {
            Log.i("CHEOK", "onUpdate " + appWidgetId);

            RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout_inverse_holo_light);

            // Register an onClickListener
            Intent refreshIntent = new Intent(context, JStockAppWidgetProvider.class);
            refreshIntent.setAction(REFRESH_ACTION);
            refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT);            
            remoteViews.setOnClickPendingIntent(R.id.refresh_button, …
Run Code Online (Sandbox Code Playgroud)

android

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

property_exists 不适用于动态生成的类属性

我有以下 PHP 类,其属性是在运行时动态生成的。

<?php

class ParamEx
{
    private $params = array();

    public function __get($name) {
        return $this->params[$name];
    }

    public function __set($name, $value) {
        $this->params[$name] = $value;
    }
};

$paramEx = new ParamEx();
$property = "dummy_property";
$paramEx->$property = "123";

// "123" printed
echo $paramEx->$property . "\n";

// Nothing printed
echo property_exists($paramEx, $property) . "\n";
Run Code Online (Sandbox Code Playgroud)

我意识到property_exists不适用于这种情况。

有什么办法可以让它发挥作用吗?

php

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

正确的方式覆盖固定大小的自定义视图

我有黄色背景的自定义视图.我打算添加一个红色背景TextView,上面有宽度和高度的match_parent.这就是我所做的.

MainActivity.java

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LinearLayout mainView = (LinearLayout)this.findViewById(R.id.screen_main);
        RateAppBanner rateAppBanner = new RateAppBanner(this);
        mainView.addView(rateAppBanner);
    }
}
Run Code Online (Sandbox Code Playgroud)

RateAppBanner.java

public class RateAppBanner extends LinearLayout {

    public RateAppBanner(Context context) {
        super(context);

        setOrientation(HORIZONTAL);

        LayoutInflater.from(context).inflate(R.layout.rate_app_banner, this, true);

        this.setBackgroundColor(Color.YELLOW);
    }
}
Run Code Online (Sandbox Code Playgroud)

rate_app_banner.xml

<?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:orientation="horizontal">

    <TextView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textColor="#ffffffff"
        android:background="#ffff0000"
        android:text="Hello World" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

现在,我希望有一个固定的宽度和高度自定义视图.我意识到,在我修复宽度和高度自定义视图后,添加的TextView不遵循match_parent属性.

这是我在自定义视图上所做的更改.

RateAppBanner.java

public class …
Run Code Online (Sandbox Code Playgroud)

android

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

安装ng-mouseover和ng-mouseout会导致效率极低的AngularJS代码

我意识到当我安装ng-mouseoverng-mouseout事件回调时,我的整个AngularJS变得非常慢.

很快,我意识到2个回调,只需移动鼠标,就会一次又一次地重新评估其他AngularJS函数.

HTML代码

<html ng-app="phonecatApp">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
  <script src="controllers.js"></script>
</head>
<body ng-controller="PhoneListCtrl"
  ng-mouseover="onScreen($event)"
  ng-mouseout="offScreen($event)">

  <div id="dummy"
    ng-show="isLoggedIn()">
    <ul>
      <li ng-repeat="phone in phones">
        <span>{{phone.name}}</span>
        <p>{{phone.snippet}}</p>
      </li>
    </ul>
  </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

controllers.js

var phonecatApp = angular.module('phonecatApp', []);

phonecatApp.controller('PhoneListCtrl', function ($scope) {
  $scope.phones = [
    {'name': 'Nexus S',
     'snippet': 'Fast just got faster with Nexus S.'},
    {'name': 'Motorola XOOM™ with Wi-Fi',
     'snippet': 'The Next, Next Generation tablet.'},
    {'name': 'MOTOROLA XOOM™',
     'snippet': 'The Next, Next Generation tablet.'}
  ];

  $scope.onScreen …
Run Code Online (Sandbox Code Playgroud)

html javascript angularjs

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

如何使用cassandra的timestamp列作为WHERE条件执行查询

我有以下Cassandra表

cqlsh:mydb> describe table events;

CREATE TABLE mydb.events (
    id uuid PRIMARY KEY,
    country text,
    insert_timestamp timestamp
) WITH bloom_filter_fp_chance = 0.01
    AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'}
    AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99.0PERCENTILE';
CREATE INDEX country_index ON mydb.events (country);
CREATE …
Run Code Online (Sandbox Code Playgroud)

cassandra

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

InputTextLayout的浮动文本和提示文本是否可以具有不同的字体

目前,我希望对的浮动文本产生大胆的影响InputTextLayout。这就是我在做什么

this.usernameTextInputLayout.setTypeface(Utils.ROBOTO_BOLD_TYPE_FACE);
Run Code Online (Sandbox Code Playgroud)

它按预期工作。浮动文本(用户名)已变为粗体。

在此处输入图片说明

但是,这将给我带来另一种不良影响。提示文本也将变为粗体。

在此处输入图片说明

您可以比较上面的两个图像。请注意,出于比较目的,我照passwordTextInputLayout原样离开。

的浮动文本和提示文本是否可以具有不同的字体InputTextLayout

android android-fonts

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