小编Prm*_*ths的帖子

使用Canvas.drawColor()清除画布

我试图改变自定义视图的背景图像,但取得了一些成功.图像会改变,但问题是我仍然看到旧图像的痕迹.当我在绘制新图像之前尝试清除画布时,它似乎不起作用.我创建一个位图来存储图像.在更改图像时,我在绘制新图像之前调用Canvas.drawColor(),但旧图像仍然存在.我已经尝试过drawColor(0),drawColor(Color.BLACK),c.drawColor(0,PorterDuff.Mode.CLEAR),并且没有上述工作.因此,我不得不发布这篇文章,以便从比我更有经验的思想中进行审核.

实际代码如下:

private int bgnd;
private boolean switching;

public void setBgnd(int incoming){
    switching = true;
    switch (incoming){

    case R.drawable.image1:
        bgnd = incoming;
        this.invalidate();
        break;

    case R.drawable.image2:
        bgnd = incoming;
        this.invalidate();
        break;

    }
}



protected void onDraw(Canvas c){
    if(switching == true){
        Bitmap b = BitmapFactory.decodeResource(getResources(), bgnd);
        c.drawColor(0, PorterDuff.Mode.CLEAR);
        c.drawBitmap(b, 0, 0, null);
        switching = false;

    }else{
        Bitmap b = BitmapFactory.decodeResource(getResources(), bgnd);
        c.drawBitmap(b, 0, 0, null);
    }
}
Run Code Online (Sandbox Code Playgroud)

android canvas ondraw

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

无法连接到AWS托管的Bitnami实例中的phpmyadmin

我正试图通过我的公共DNS连接到phpmyadmin,我似乎无法让它工作.

我试过按照这些指示:

无法访问PHPMyAdmin

默认情况下,phpMyAdmin仅限于localhost.如果您希望可以从任何地方访问它,您应该按照虚拟机中的"如何启用phpMyAdmin或phpPgAdmin?"中描述的步骤进行操作FAQ:

SSH到实例在文件/opt/bitnami/apps/phpmyadmin/conf/phpmyadmin.conf中用"Allow from all"替换"Allow from 127.0.0.1"行重新启动apache:sudo /opt/bitnami/ctlscript.sh restart阿帕奇

此解决方案的问题是我在该目录中没有phpmyadmin.conf文件.我发现这与phpmyadmin文件夹中不存在Phpmyadmin.conf相关,但是这不允许我访问.

检查/opt/bitnami/apps/phpmyadmin/htdocs/config.inc.php并使用您的URL更改"$ cfg ['PmaAbsoluteUri']"选项.

我仍然得到同样的For security reasons, this URL is only accesible using localhost (127.0.0.1) as the hostname错误,这让我很生气.

有任何想法吗?如果需要,我可以随时发布配置文件中的相关内容.

phpmyadmin amazon-ec2 bitnami amazon-web-services

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

将 ArrayList 内的对象序列化为 XML 时丢失类型元素

我在使用 Jackson 序列化为 XML 时似乎遇到了问题。我的代码如下:

测试容器

package com.test;

import java.util.ArrayList;

import com.fasterxml.jackson.annotation.JsonProperty;

public class TestContainer {

    private String testContainerID;
    private String testContainerMessage;
    private ArrayList<TestChild> testContainerChildren;

    @JsonProperty("TestContainerID")
    public String getTestContainerID() {
        return testContainerID;
    }

    @JsonProperty("TestContainerID")
    public void setTestContainerID(String testContainerID) {
        this.testContainerID = testContainerID;
    }

    @JsonProperty("TestContainerMessage")
    public String getTestContainerMessage() {
        return testContainerMessage;
    }

    @JsonProperty("TestContainerMessage")
    public void setTestContainerMessage(String testContainerMessage) {
        this.testContainerMessage = testContainerMessage;
    }

    @JsonProperty("TestContainerChildren")
    public ArrayList<TestChild> getTestContainerChildren() {
        return testContainerChildren;
    }

    @JsonProperty("TestContainerChildren")
    public void setTestContainerChildren(ArrayList<TestChild> testContainerChildren) {
        this.testContainerChildren = testContainerChildren;
    }

} …
Run Code Online (Sandbox Code Playgroud)

xml-serialization jackson fasterxml json-deserialization

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

Robolectric不使用ShadowWebView作为扩展WebView的类的超类.而是MustOverrideException

我试图让Robolectric 2.1与我的项目一起工作并在我的WebView子类尝试在其WebSettings上调用setDatabasePath时获取MustOverrideException.我有一个自定义Application类,它尝试在onCreate中创建WebView子类的实例.作为WebView构造函数的一部分,它尝试设置数据库路径.

我原本以为,因为getSettings是从WebView调用的,所以调用会真正击中ShadowWebView,它应该返回一个不会抛出这些异常的TestWebSettings对象.相反,它似乎只是调用正常的WebSettings.getSettings并返回没有实现这些方法的东西.我尝试使用@Config(shadows = ShadowWebView.class)进行测试,但没有任何变化.我试图创建我的专业Web视图的自定义阴影并将其应用于测试,但它仍然调用常规自定义类.这是我尝试运行测试时看到的异常:

java.lang.RuntimeException: android.webkit.MustOverrideException: abstract function called: must be overriden!
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:231)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355) …
Run Code Online (Sandbox Code Playgroud)

android unit-testing webview robolectric

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

将ImageView对齐到LinearLayout的右下角

我正在试图将一个ImageView放在LinearLayout的右下角....我把代码编写为:

style.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="90dp"
        android:background="@drawable/my_background"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:src="@drawable/my_small_image" />

        </LinearLayout>

    <ListView  
        android:id="@android:id/list"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"/>

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

此代码导致右下角的ImageView"my_small_image",但我需要在左下角.有人对此有什么想法吗?

我希望这里有人可以帮助我.

最好的问候和提前感谢,Fadel.

android android-layout

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

免费访问受保护的成员

我创建了一个类,它有几个protected成员,可以被其他类完全访问:

class MyClass {
    protected String name;
}
Run Code Online (Sandbox Code Playgroud)

在我看来,这不应该编译:

MyClass mc = new MyClass();
mc.name = "foo";
Run Code Online (Sandbox Code Playgroud)

但它工作正常.当我成为会员时private,它按预期工作.怎么会这样?

一些注意事项,但我认为它们应该没有任何区别:

  • mc里面HashMap,
  • 我在里面访问它 Activity

java protected

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

难以解析Android项目的rss feed

我正在尝试创建一个RSS feed解析应用程序,我是Android编程的新手.我目前有一个主活动,它会提示用户输入一个rss URL,以及所请求的rss feed的maxRows.我正在使用ROME库在Java中进行RSS feed解析.以下是我的代码:

package com.xetur.simplerss;

import java.io.IOException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

    public class ListRowsActivity extends Activity {
        private URL url;
        private int maxRows;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_list_rows);
            readFeed();
            new Thread(new Runnable() {
                public void run() {
                    readFeed();
                }
            }).start();
        }

        @SuppressWarnings("deprecation")
        private void readFeed() {
            XmlReader reader = …
Run Code Online (Sandbox Code Playgroud)

java rss android rome

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