小编Adi*_*nia的帖子

"GONE"观点是否被夸大了?

我有一个巨大的XML布局,有很多Relative / Linear布局,我现在正在做的是隐藏我不需要的所有布局,setVisibility (View.GONE)并在需要时改变它们的可见性.

我的问题是:这种方法足够吗?膨胀和渲染的布局是如何改变手机内存及其活动加载的性能和时间,或直到我设置可见性为止VISIBLE.

布局越来越大,所以我想知道我是否应该使用Fragments或保持现在的状态.

performance android android-layout

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

Glide断言:java.lang.IllegalArgumentException:您必须在主线程上调用此方法

有没有人用Glide从后台线程中获取图像?我一直得到这个断言:

java.lang.IllegalArgumentException: You must call this method on the main thread
Run Code Online (Sandbox Code Playgroud)

但根据这个线程,它应该工作:

https://github.com/bumptech/glide/issues/310

然而,我不能让它工作,除非我从主线程中调用它.

这是我试图从主线程做的事情:

    Glide.get(mContext);
    loadUserImage(userImageUrl);

    // wait 5 seconds before trying again
    int imageLoadingTimeOut = mContext.getResources().getInteger(R.integer.image_loading_time_out);
    if (imageLoadingTimeOut > 0) {
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                if (!mUserImageLoaded) {
                    loadUserImage(userImageUrl);
                }
            }
        }, imageLoadingTimeOut);
    }
}
Run Code Online (Sandbox Code Playgroud)

和loadUserImage:

private boolean mUserImageLoaded = false;

private void loadUserImage(String userImageUrl) {

    if (userImageUrl != null && !userImageUrl.isEmpty() && !mUserImageLoaded) {
        Glide.with(mContext).using(Cloudinary.getUrlLoader(mContext)).load(userImageUrl).crossFade().listener(new RequestListener<String, GlideDrawable>() {

            @Override
            public boolean onException(Exception …
Run Code Online (Sandbox Code Playgroud)

multithreading android android-glide

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

将Android Studio升级到3.2.1后合并清单警告

升级到Android Studio 3.2.1,在编辑AndroidManifest.xml文件时,我看到文件的<application>部分以黄色突出显示(可能是由于下面的警告).我还看到一个新标签Merged Manifest,其中包含警告:

合并错误:警告活动#com.google.firebase.auth.internal.FederatedSignInActivity@android:启动模式已标记为AndroidManifest.xml:24以替换其他声明,但没有其他声明存在应用程序主清单(此文件),第23行

问题:

  1. 这个新标签在AS 3.2.1中是新的吗?或者它是否出现,因为AS 3.2.1发现了一个新的警告,以前的版本没有?

  2. 有什么警告?出于某种原因,我是否需要在我的应用的AndroidManifest.xml for Firebase中添加活动?

  3. 我如何解决它?

(注意:大约在同一时间可能还有Firebase更新.)

Firebase目前是最新的.

implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-crash:16.2.1'
Run Code Online (Sandbox Code Playgroud)

尽管如此,一切都汇编并运行良好.

android-manifest firebase android-studio

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

SCREEN_ORIENTATION_USER和SCREEN_ORIENTATION_SENSOR之间的区别

在开发Android应用程序时,我发现了两个用于设置屏幕方向的ActivityInfo属性.

具有USER的属性如下:

  1. SCREEN_ORIENTATION_USER
  2. SCREEN_ORIENTATION_USER_LANDSCAPE
  3. SCREEN_ORIENTATION_USER_PORTRAIT

具有SENSOR的属性如下:

  1. SCREEN_ORIENTATION_SENSOR
  2. SCREEN_ORIENTATION_SENSOR_LANDSCAPE
  3. SCREEN_ORIENTATION_SENSOR_PORTRAIT

SCREEN_ORIENTATION_USER和SCREEN_ORIENTATION_SENSOR之间有什么区别?

android orientation screen-orientation

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

如何自定义使用"Surround with try/catch"时生成的代码?

每个Android开发人员都陷入了下一种情况:

public void catchMeThod() {
    throwedMethod();
}

public void throwedMethod() throws IOException{
    throw new IOException("File is missing.");    
}
Run Code Online (Sandbox Code Playgroud)

由于IOExceptionChecked异常throwedMethod迫使我们处理它.

当我将插入符号移到内部throwedMethod并按下时Alt + Enter,Android Studio为我提供了一些可能的场景:

![在此处输入图像说明

默认情况下,我选择该Surround with try/catch选项,Android Studio生成下一个代码:

在此输入图像描述

我的问题是:如何更改此触发器,以替换

e.printStackTrace() 
Run Code Online (Sandbox Code Playgroud)

Log.e(getClass().getSimpleName(), "Handled exception", e);
Run Code Online (Sandbox Code Playgroud)

android intellij-idea android-studio

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

多个通知,只显示第一个Android

我正在创建一个必须显示超过1个通知的应用.我正在查找信息,我在课堂上使用此代码:

Notification noti = new NotificationCompat.Builder(this)
Run Code Online (Sandbox Code Playgroud)

我可以在栏上显示多个通知,但问题是当我点击它时只显示第一个.我认为它是因为挂起的intent获得的id总是相同的,但是我发送了一个不同的id.

通知活动:单击按钮时显示新通知.

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.view.View;

public class NotificationActivity extends Activity {
int notificationID = 1;

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

public void onClick(View v){
    displayNotification();
}

protected void displayNotification(){
    Intent i = new Intent(this, NotificationView.class);
    i.putExtra("notificationID", notificationID);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, 0);
    NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

    CharSequence ticker ="Display";
    CharSequence contentTitle = …
Run Code Online (Sandbox Code Playgroud)

notifications android android-notifications

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

如何获得覆盖请勿打扰设置值?

如何在Android中为我自己的软件包应用程序获取覆盖请勿打扰设置状态?

在此输入图像描述

android android-notifications

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

类inf <unknown>时出错

我正试图在UI中工作.我正在尝试为列表条目设置stateListDrawable.我想要做的就是在按下项目时更改列表项目布局的颜色,并且在按下列表项目时我也想要更改文本的颜色.

我收到以下错误堆栈:

E/AndroidRuntime(  360): FATAL EXCEPTION: main
E/AndroidRuntime(  360): android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
E/AndroidRuntime(  360):    at android.view.LayoutInflater.createView(LayoutInflater.java:513)
E/AndroidRuntime(  360):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime(  360):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
E/AndroidRuntime(  360):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
E/AndroidRuntime(  360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
E/AndroidRuntime(  360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime(  360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
Run Code Online (Sandbox Code Playgroud)

膨胀的XML如下:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/help_list_container"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5dip"
    android:background="@drawable/default_list_selection">
    <TextView android:id="@+id/help_list_text" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textColor="@drawable/help_text_color">
    </TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

如果我android:textColor从xml中删除属性,我可以让程序工作.有没有办法可以使用stateListDrawable来控制xml中的listitem的texColor?

stateListDrawable适用android:background于LinearLayout,但不适用于TextView的textColor属性.状态列表xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/white"
              android:state_pressed="true" …
Run Code Online (Sandbox Code Playgroud)

android textview android-inflate xml-drawable

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

如何更改同一列中的多个日期格式

到目前为止我所拥有的是一个数据帧列,其中包含不同字符格式的日期.一些出现在%d.%m.%Y模式中,一些出现在%m/%d/%Y:

data$initialDiagnose = as.character(data$initialDiagnose)
data$initialDiagnose[1:10]

[1] "14.01.2009" "9/22/2005"  "4/21/2010" "28.01.2010" "09.01.2009" "3/28/2005" "04.01.2005" "04.01.2005" "9/17/2010" "03.01.2010"
Run Code Online (Sandbox Code Playgroud)

我希望它们以一种格式作为Date(),但R当然拒绝.
所以我首先尝试通过分隔符更改它们:

data$initialDiagnose[grep('/', data$initialDiagnose)] = as.character.Date(data$initialDiagnose[grep('/', data$initialDiagnose)], format = '%m/%d/%Y')
Run Code Online (Sandbox Code Playgroud)

类似于'.' 日期.但它没有用.

如何将它们全部更改为一种格式,我可以使用它们?

format r date

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

在使用名称中的时间戳时,Android Studio无法在构建后启动应用程序

我在使用gradle和Android Studio时出现问题,只有在Android Studio中构建时才会出现(BuildServer和Commandline工作正常)

applicationVariants.all { variant ->
            def file = variant.outputFile
            variant.outputFile = new File(file.parent, file.name.replace("app-", getDate() + "_myapp_" + getGitCommit() +"_"));
        }

def getDate() {
        def dateNow = new Date()
        def formattedDate = dateNow.format('yyyy-MM-dd_HH-mm-ss')
        return formattedDate
}
Run Code Online (Sandbox Code Playgroud)

构建工作,但当AS想要将apk复制到设备时,它会抛出Local path doesn't exist.错误.

问题是生成的文件如下所示:

2014-03-17_16-17-41_myapp__debug-unaligned.apk
Run Code Online (Sandbox Code Playgroud)

但AS寻找:

2014-03-17_16-17-18_myapp__debug-unaligned.apk
Run Code Online (Sandbox Code Playgroud)

这是由AS特定的构建步骤以某种方式生成的,导致重新计算日期.我尝试用构建日期的外部属性修复它,在整个构建过程中应保持相同,但可能由于我缺乏gradle技能,这没有帮助.

也许某人有一个解决方法让我在Android Studio中使我的构建工作.

android gradle android-studio

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