小编Atu*_*lic的帖子

ImageView adjustViewBounds不起作用

我有一个ImageView android:layout_width=100dp,android:layout_height=wrap_contentandroid:adjustViewBounds=true

它的来源是50 x 50像素的图片.但不保留纵横比 - ImageView的高度为50px,而不是100px(即adjustViewBounds不工作).如果我有一个200x200px的图片它可以工作 - 宽度和高度是100px.此代码生成100px宽和50px高的图片,但src图像是正方形:

<?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">

    <ImageView
        android:id="@+id/photo"
        android:src="@drawable/icon"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:adjustViewBounds="true" />

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

android imageview android-imageview

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

Facebook App Invite,邀请朋友

我切换到Facebook 4.0以实现Android的AppInviteDialog.我按照这个参考.

出现对话框,我可以选择朋友,邀请他们,我onSuccess()接到电话,但我的朋友没有得到邀请.

我使用了以下applink网址:https://fb.me/****412097*****

虽然我在对话框中看到了应用程序的图像,但没有previewImageURL.

码:

//Inside onCreate -

        callbackManager = CallbackManager.Factory.create();

        mInvititeDialog = new AppInviteDialog(this);
        mInvititeDialog.registerCallback(callbackManager,
                new FacebookCallback<AppInviteDialog.Result>() {

                    @Override
                    public void onSuccess(Result result) {
                        NetworkController.showCustomToast(
                                InviteFriendsActivity.this,
                                "Invitation Sent Successfully!");
                        finish();
                    }

                    @Override
                    public void onCancel() {
                        Log.d("Result", "Cancelled");
                        NetworkController.showCustomToast(
                                InviteFriendsActivity.this, "Cancelled");
                        finish();
                    }

                    @Override
                    public void onError(FacebookException exception) {
                        Log.d("Result", "Error " + exception.getMessage());
                        NetworkController.showCustomToast(
                                InviteFriendsActivity.this,
                                "Error while inviting friends");
                        finish();
                    }
                });


    if (AppInviteDialog.canShow()) {
            AppInviteContent content = new AppInviteContent.Builder()
                            .setApplinkUrl(appLinkUrl).build();

            AppInviteDialog.show(InviteFriendsActivity.this, content); …
Run Code Online (Sandbox Code Playgroud)

android facebook facebook-app-requests facebook-invite facebook-invite-friends

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

Android应用,活动状态(正在运行,未运行,前景/背景)

我遇到了一个要求,但我无法得到正确的实施方式,因此需要你的帮助.

我想做的事? - 我想根据我得到的通知执行操作如下:

  1. 当应用程序打开并处于前台时,即用户可见,我收到通知,我只需显示一个弹出窗口即可启动我的活动B.
  2. 当应用程序关闭时,即无论是在后台还是在前台,我都会收到通知,我将首先启动我的应用程序然后启动活动B.
  3. 当应用程序在后台运行时,即在最近但用户不可见时,我想启动我的活动B而不重新启动应用程序.此外,在这种情况下,当用户按下活动B时,他们应该在将其发送到后台之前看到他们停止的屏幕.

我做了什么?我已经取得了第一点和第二点.我想达到第3点.我试过以下

public static boolean isApplicationBroughtToBackground(final Activity activity) {
  ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
  List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1);

  // Check the top Activity against the list of Activities contained in the Application's package.
  if (!tasks.isEmpty()) {
    ComponentName topActivity = tasks.get(0).topActivity;
    try {
      PackageInfo pi = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_ACTIVITIES);
      for (ActivityInfo activityInfo : pi.activities) {
        if(topActivity.getClassName().equals(activityInfo.name)) {
          return false;
        }
      }
    } catch( PackageManager.NameNotFoundException e) {
      return false; // Never happens.
    }
  }
  return true;
} …
Run Code Online (Sandbox Code Playgroud)

android activity-lifecycle android-activity android-task

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

Android模糊视图(视图背后的模糊背景)

我试图让图像的底部部分为顶部的视图,就像在图像中一样.

我尝试使用Rendenscript模糊它,但我无法模糊视图背后的部分.:(

我见过很多库,但几乎所有库都模糊了整个图像,但不是它的一部分.

另外,一个重要的部分是我在ViewPager中使用它,因此在IOS中需要像这样快速和动态的东西,它在它背后的图像改变时重绘自己.

任何帮助表示赞赏.谢谢你的到来!

我的xml:

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

    <ImageView
        android:id="@+id/image"
        android:src="@drawable/broadstairs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:layout_centerInParent="true"/>

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:text="Hello World"
        android:gravity="center"
        android:layout_alignParentBottom="true"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        android:textSize="36sp"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我的代码:

BlurBuilder.java

public class BlurBuilder {
    private static final float BITMAP_SCALE = 0.1f;
    private static final float BLUR_RADIUS = 7.5f;

    public static Bitmap blur(Context context, Bitmap image) {
        int width = Math.round(image.getWidth() * BITMAP_SCALE);
        int height = Math.round(image.getHeight() * …
Run Code Online (Sandbox Code Playgroud)

android blur blurry android-image android-bitmap

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

向导航抽屉添加线性布局(最终导致与ClassCastException崩溃)

我试图在导航抽屉中添加垂直线性布局(标题,图像,菜单标题,列表视图和底部的图标).然而,应用程序崩溃显示

'java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams'
Run Code Online (Sandbox Code Playgroud)

错误.我不确定这是否可能是直接的方式,因为我检查了几个链接,我得到的唯一关闭是这个.任何帮助表示赞赏.提前致谢.这是我的代码.

<!-- The main context view -->

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<!-- The navigation drawer -->

<LinearLayout        
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#fff"
    android:gravity="bottom|center"
    android:orientation="vertical"
    android:paddingTop="30dp" >

    <ListView
        android:id="@+id/left_drawer"                        
        android:choiceMode="singleChoice"
        android:divider="#E8E8E8"
        android:dividerHeight="1dp"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:padding="10dp"
        android:src="@drawable/footer_image" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

现在的问题是,xml不允许我为listview定义宽度和高度(Element未知),我也无法运行它,因为编译器说"你必须提供layout_width"属性?请帮忙.

我的代码与scrollview.

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<!-- The main context view -->

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<!-- The navigation drawer -->

<ScrollView
    android:id="@+id/leftRL"
    android:layout_width="240dp"
    android:layout_height="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android navigation-drawer

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

Android Cookies(邀请奖励)

我正在尝试整合"奖励邀请"逻辑.我想为此做的是为每个用户生成一个独特的URl.当朋友点击该URL时,他将被定向到一个页面,然后被定向到该Playstore.在页面上,具有唯一ID的cookie存储在设备上.

注 - (用户可以在任何浏览器中打开链接)

当设备上的应用程序启动时,我会获取使用上面保存的cookie,如果可用,则将其发送到服务器,用户可以轻松识别并获得奖励.

这看起来很直接,但是我被困在我必须阅读cookie并提取id的位置.

我读到说不可能.:(我也试过以下

List<Cookie> cookies = new DefaultHttpClient().getCookieStore()
            .getCookies();
    if (cookies.isEmpty()) {
        System.out.println("None Cookies");
    } else {
        for (int i = 0; i < cookies.size(); i++) {
            System.out.println("Cookie - " + cookies.get(i).toString());
        }
    }
Run Code Online (Sandbox Code Playgroud)

但没有运气.我一直收到"无饼干".

我的问题:

  1. 是否可以读取创建的cookie?如果有,怎么样?
  2. 如果没有,关于如何实现上述功能的任何替代方案?

谢谢你的光临.

cookies android google-chrome android-browser

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

使用屏幕键盘输入时,Android中的EditText不显示文本

我有一个由3个EditText字段组成的活动(以及其他诸如TextViews和一些按钮)。我也有一个使用ArrayAdapter的String列表的AutoCompleteTextView。

每当我在模拟器中测试该应用程序时,我都可以在键盘启动时进行键入,但它不会显示文本(仍会提供预测),并且仅在键盘关闭时该文本才会显示在EditText框中。当我也在手机上进行测试时,也会发生这种情况。但是,如果屏幕上的键盘没有弹起,而您只是在正常键入,则在您在模拟器上键入时,它将起作用并显示。

我不知道为什么!

这是我的Activity XML(其中EditText是前3个块)

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/l"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_x="3dp"
    android:layout_y="5dp"
    android:background="@drawable/gymbg" >


   <AutoCompleteTextView android:id="@+id/inputExercise"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:completionThreshold="1"
        android:inputType="text"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/timeSet"
        android:layout_margin="10dp"
        android:layout_marginTop="50dp"
        android:width="200dp" />  

    <EditText
        android:id="@+id/inputWeight"
        android:inputType="number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/inputExercise"
        android:layout_margin="10dp"
        android:layout_marginTop="50dp"
        android:width="200dp" >
    </EditText>

    <EditText
        android:id="@+id/inputReps"
        android:inputType="number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/inputWeight"
        android:layout_margin="10dp"
        android:layout_marginTop="50dp"
        android:width="200dp" >
    </EditText>

    <TextView
        android:id="@+id/timeMain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="@string/timeMain"
        android:textSize="32sp" 
        android:textColor="#0F293B"/>

    <TextView
        android:id="@+id/timeSet"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/timeMain"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="24dp"
        android:text="@string/timeSet" 
        android:layout_marginBottom="50dp"
        android:textColor="#0F293B"/>

    <TextView
        android:id="@+id/labExercise"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/addbutton"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/timeSet"
        android:layout_centerVertical="true"
        android:layout_margin="10dp" …
Run Code Online (Sandbox Code Playgroud)

eclipse android android-edittext

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

Android Sqlite 存储限制

我正在开发一个 android 应用程序,它每 30 秒获取一次用户位置并存储在应用程序自己的 sqlite 数据库中。在我的计算中,我需要存储大约 1 个 Lac 记录。我只有 1 个表,其中包含以下详细信息:ID(整数)、纬度(实数)、经度(实数)、日期(文本)、时间(文本)。

将详细信息存储在 sqlite 中是否安全?

它会导致性能方面的任何问题。

请帮我。

sqlite android

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

浮点数的 Ruby 正则表达式

我在用 ruby​​ 构建浮点数时遇到问题。

该数字可以是负数也可以是正数。

可以是这样的:0.00000020402(如果数字小于 1,则小数点前必须有 1 个零。

0.5 是正确的方法,但不是 0.5

这是唯一的规则,否则,其他任何规则都可以,如下所示:

-0.4224(负)或-0.00002(负)或5.2525

那么有人可以帮助我了解涵盖这些浮点数情况的正则表达式是什么吗?

这是我到目前为止所拥有的:^[+-]?(?:(?!0)\d{1,2}|0)(?:.[05])?$

ruby regex

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

SlidingPaneLayout背景颜色

我正在使用SlidingUpPanel.一切都很好.:)我想要实现的是将图像中面板的背景颜色更改为透明,以便显示其后面的图像部分.我尝试将SLidingPaneLayout的背景颜色设置为透明,但它不起作用.当我将颜色更改为红色等其他颜色时,它会显示红色但不会发生透明相同的颜色.

我也尝试将窗口背景设置为透明,但它留下了黑色背景.

Window window = this.getWindow();
window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Run Code Online (Sandbox Code Playgroud)

请帮忙.

在此输入图像描述

<?xml version="1.0" encoding="utf-8"?>
<com.app.custom.SlidingUpPanelLayout     xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:blurView="http://schemas.android.com/tools"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoDragView="@+id/dragView"
sothree:umanoPanelHeight="110dp"
sothree:umanoParalaxOffset="0dp"
sothree:umanoShadowHeight="0dp">

<!-- MAIN CONTENT -->


<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imgProfileLarge"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@null"
        android:scaleType="centerCrop"
        android:src="@drawable/profile" />

    <RelativeLayout
        android:id="@+id/layoutDetails"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="gone">


        <com.app.custom.UnscrollableViewPager
            android:id="@+id/facesPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true" />


        <com.app.custom.CirclePageIndicator
            android:id="@+id/indicator"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerInParent="true"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="10dp"
            android:padding="10dp" />

    </RelativeLayout>

</FrameLayout>


<!-- SLIDING LAYOUT -->

<com.app.custom.FrameLayoutWithBluredBackground
    android:id="@+id/dragView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:focusable="false"
    blurView:blurRadius="20">


    <ViewFlipper
        android:id="@+id/mViewFlipper"
        android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-sliding slidingmenu android-background

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

FCM通知未在Oreo的后台调用

当用户未连接到xmpp时,我正在使用FCM通知进行聊天.

FCM中有2种通知模式1.通知消息2.数据消息

如果我的应用程序从最近清除,我将使用数据消息作为通知消息

这种方法适用于除Oreo之外的所有版本.

对于Oreo,如果应用程序未连接到xmpp和前台,我只会收到通知.我的onMessageReceived方法被调用了.

但是,当应用程序被杀死或仅从Oreo中删除时,同样的情况也不会发生.

编辑:我试过One Plus 3设备.

任何帮助表示赞赏.

android firebase firebase-cloud-messaging android-8.0-oreo

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