小编zys*_*zys的帖子

如何在"onBindViewHolder"中获取recyclerview项目的高度

RecyclerView项目的高度不固定,我需要为每个项目设置背景图像,所以我想获得recyclerview项目的高度来调整Image的大小,但 itemView.getHeight()总是返回0 in onBindViewHolder.

我试着搜索很多问题或文章,但我仍然无法获得良好的解决方案.

android kotlin android-recyclerview

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

Android Nested Scrollview不滚动

我有一个嵌套ScrollView,其中包含线性布局内的内容.

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:CoverFlowPager="http://schemas.android.com/apk/res-auto"
    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">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:clipToPadding="false"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

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

我在ViewPager中有这个布局,ViewPager在CordinatorLayout里面.

<android.support.design.widget.CoordinatorLayout 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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
Run Code Online (Sandbox Code Playgroud)

现在,当我滚动视图时,视图不会滚动.但由于布局位于Cordinator布局内,因此向上移动直到ToolBar被隐藏.但它没有向上滚动.

这是我的主要活动xml,视图寻呼机位于选项卡式布局中.

<android.support.design.widget.CoordinatorLayout 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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

           <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                xmlns:attrs="http://schemas.android.com/apk/res-auto"
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/AppTheme.PopupOverlay">

            <FrameLayout
                android:id="@+id/titleContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"    
                android:gravity="center">

                <com.CustomFontTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Toolbar Title"
                    android:textColor="#ffffff"
                    attrs:customFont="handyman_bold"
                    android:textSize="8pt"
                    android:layout_marginLeft="-20dp"
                    android:id="@+id/toolbar_title"/>
            </FrameLayout>

            <ImageButton
                android:id="@+id/btn_ToolBarRightBtn"
                android:layout_width="32dp"
                android:layout_height="28dp"
                android:tag="0" …
Run Code Online (Sandbox Code Playgroud)

android android-nestedscrollview

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

谷歌界面X509TrustManager的不安全实现

我在谷歌播放应用程序,我收到了谷歌的一封邮件说:

您在此电子邮件末尾列出的应用使用了界面X509TrustManager的不安全实现.具体而言,在与远程主机建立HTTPS连接时,实现会忽略所有SSL证书验证错误,从而使您的应用容易受到中间人攻击.

要正确处理SSL证书验证,请在自定义X509TrustManager接口的checkServerTrusted方法中更改代码,以便在服务器提供的证书不符合您的期望时引发CertificateException或IllegalArgumentException.

我的应用使用"https",我checkServerTrusted()的内容如下:

 TrustManager tm = new X509TrustManager() {
        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {

        }

        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    };
Run Code Online (Sandbox Code Playgroud)

然后我修改这个功能:

 TrustManager tm = new X509TrustManager() {
        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            if (chain == null) {
                throw new IllegalArgumentException("checkServerTrusted: X509Certificate array is null");
            }

            if …
Run Code Online (Sandbox Code Playgroud)

java android sslsocketfactory android-security trustmanager

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

"createBitmap" 和 "createScaledBitmap" 有什么区别,当得到固定的高度和宽度照片时

我想导入一张照片,然后在 ImageView 中显示它的“高度”和“宽度”是固定的。首先,我输入 pohot byBitmapFactoryoptions.inSampleSize获取位图。第二,我想获取照片,但我不知道我可以在createScaledBitmap(Bitmap src, int dstWidth, int dstHeight)createBitmap(Bitmap source, int x, int y, int width, int height)

我看过Android Developer文档,但我仍然模糊。我认为createScaledBitmap改变了照片的大小,但是createBitmap可以随心所欲地剪切照片。

 public static Bitmap getBitmap(String filePath, String fileName, int reqWidth, int reqHeight) {


    if (filePath.length() <= 0 || filePath == null) {
        return null;
    }
    String fullPath = filePath+"/"+fileName;
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(fullPath, options);
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds …
Run Code Online (Sandbox Code Playgroud)

android bitmap

5
推荐指数
0
解决办法
739
查看次数

无法解决:com.google.firebase:firebase-analytics:9.0.0

根据谷歌I/O 2016,我知道"Firebase",它对我来说非常好,但我不能使用它,因为这个错误.我已经得到一个解决方案,将"Google Play服务"更新为30,但没有更新提示.

在此输入图像描述

android firebase google-play-services firebase-analytics

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