小编Pri*_*ish的帖子

将ConstraintLayout中的FrameLayout对齐到底部

我希望屏幕底部的回收视图上方有一个布局(如框架),这样即使该布局可见,我仍然可以在其后面滚动回收视图.所以我想在屏幕底部对齐框架布局并制作它根据要求可见和不可见.这是我的代码.

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.protossoft.root.aesencryption.MainActivity">



    <ListView
        android:layout_width="match_parent"
        android:id="@+id/listView"
        android:layout_height="match_parent">

    </ListView>

  <!--  <RelativeLayout
        android:layout_width="match_parent"

        android:layout_height="wrap_content">-->
    <FrameLayout
        android:layout_width="match_parent"

        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="443dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:gravity="center"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/deviceNumberImage"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.2"
                android:src="@android:drawable/btn_default" />

            <TextView
                android:id="@+id/deviceNumber"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.8"
                android:text="990000862471854" />

        </LinearLayout>
    </FrameLayout>
   <!-- </RelativeLayout>-->
Run Code Online (Sandbox Code Playgroud)

我对约束布局没有太多的想法,但是当我从编辑器底部移动视图时,它正在使用像

tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="443dp"
Run Code Online (Sandbox Code Playgroud)

我想用align_parentBottom这样的属性实现相同的功能.但是没有一个属性可供使用.我需要做什么才能使框架布局同时在回收器视图的底部和顶部可见?谢谢 :)

xml android android-layout android-view android-constraintlayout

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

通过滑动从背景中删除活动后,未调用活动的onDestroy()方法

ActivityLifecycleCallbacks在班级内的私人班级中实现了Application

如果使用“主页”按钮或“后退”按钮,则将调用生命周期onStop()onPause()方法。如果我通过从后台刷出来杀死活动,onDestroy()则不会调用方法。下次我开始活动时会调用它。我正在使用moveTaskToBack(true)Back Press。

从后台滑出时,问题一定是什么,应该调用哪种生命周期方法?

android

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

如何在约束布局上将图像放在图像视图的右中心

以下是我整个xml约束布局的一部分.

<ImageView
            android:id="@+id/img_apn_not_set"
            style="@style/DeviceManagementImageView"
            android:contentDescription="@string/app_name"
            android:src="@drawable/ic_sos"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/view1" />

        <TextView
            android:id="@+id/tv_apn_not_set"
            style="@style/DeviceManagementHeaderText"
            android:text="Apn not set"
            android:layout_marginTop="5dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/img_apn_not_set"

            app:layout_constraintTop_toTopOf="@+id/img_apn_not_set" />
Run Code Online (Sandbox Code Playgroud)

我想要做的是在图像视图右侧的精确中心上获取文本视图.在线性布局中,我们主要通过重力实现它.我在这里marginTop用来实现同样的目标.所以我可以通过使用任何属性来做同样的事情.是否有类似的财产rightOfCentreOf?谢谢

xml android android-layout android-constraintlayout

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

如何知道当前是否已连接BLE设备

是否有任何类似device.isConnected()的方法来了解android BLE device的当前状态。我所知道的是,我需要从GattclientCallBack类实现某种体系结构,例如接口,以了解设备是否已连接,但是我找不到这种方法。还有方法

 mBluetoothGatt.getConnectionState(device);
Run Code Online (Sandbox Code Playgroud)

返回int。那么究竟如何知道设备是否已连接?谢谢 :)

android bluetooth-lowenergy

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

删除约束布局中链式视图中两个视图之间的空间

我在约束布局中使用链式视图。现在我想删除两个文本视图之间的中间空间。因为底部的按钮相距很远。我试图将它们从设计布局中移出,但它也没有发生。怎么做。以下是我的xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout_editor_absoluteY="81dp">


    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="23dp"
        android:layout_marginStart="32dp"
        android:gravity="center"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="@+id/imageView3"
        app:layout_constraintStart_toEndOf="@+id/imageView3" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="26dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView2"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
        android:id="@+id/textViewHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <!--<LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="1dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="60dp"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/linearLayout2">-->


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="25dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="70dp"
        app:layout_constraintEnd_toStartOf="@+id/textView2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginStart="32dp"
        android:layout_marginTop="26dp"
        android:gravity="center"
        android:text="TextView"
        app:layout_constraintStart_toEndOf="@+id/imageView2"
        app:layout_constraintTop_toTopOf="@+id/imageView2" />

    <!-- </LinearLayout>--> …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

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

ArrayList数据类型中的remove()方法究竟返回了什么

我在我的代码中使用list.remove()方法.我试图将返回的值作为参数传递给某个函数作为字符串,这样它既可以返回也可以删除对象.当我在for循环中打印它时,它只显示两个元素,它应该打印4.为什么会这样?

ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");

        for(int i=0;i<list.size();i++) {
            Log.d("Removed+++++++++++","++++"+list.remove(i));
           // queue.remove();
        }
Run Code Online (Sandbox Code Playgroud)

d /移除+++++++++++:++++一
d /删除+++++++++++:++++Ç

为什么它只打印a和c时应打印a,b,c,d?

java arraylist

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

如何在kotlin中定义全局的arralist

对于android中的java类,我们习惯在Activity之类声明一个int数组,int[] intarray; 并使用intArray = new Int(size)创建所需的对象.

我知道在kotlin中使用数组我需要做类似的事情

val numbers: IntArray = intArrayOf(10, 20, 30, 40, 50)
Run Code Online (Sandbox Code Playgroud)

我无法做的只是全局声明对象,即

val numbers: IntArray
Run Code Online (Sandbox Code Playgroud)

在kotlin中,我们声明变量,val a: Int = 1但是如基本语法教程所示,它不允许我只声明变量val c: Int,然后在需要时初始化它.它给了我错误

财产必须初始化或抽象

声明部分我错了.因为它不允许我只定义val numbers: IntArray.谁能告诉我哪里出错了?

android kotlin

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

如何仅在应用程序处于开发模式时打印日志?

我只需要在开发应用程序时在我的应用程序中打印日志。那么有没有一种像布尔值这样的方法来决定我的应用程序是否处于某种模式,然后只允许打印日志?这将节省我每次准备签名构建时删除日志的时间。

我尝试了以下解决方案:

boolean isDebuggable = 0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE);
Run Code Online (Sandbox Code Playgroud)

和:

if (BuildConfig.DEBUG) {
  // do something for a debug build
}`
Run Code Online (Sandbox Code Playgroud)

它们不像我想要的那样工作。

谢谢你。

android android-logcat android-log

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