RecyclerView项目的高度不固定,我需要为每个项目设置背景图像,所以我想获得recyclerview项目的高度来调整Image的大小,但 itemView.getHeight()总是返回0 in onBindViewHolder.
我试着搜索很多问题或文章,但我仍然无法获得良好的解决方案.
我有一个嵌套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) 我在谷歌播放应用程序,我收到了谷歌的一封邮件说:
您在此电子邮件末尾列出的应用使用了界面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) 我想导入一张照片,然后在 ImageView 中显示它的“高度”和“宽度”是固定的。首先,我输入 pohot byBitmapFactory并options.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)