适配问题,相同布局不同手机展示差异- android:layout_width="wrap_content"
xml布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dp_40"
android:layout_marginLeft="@dimen/dp_36"
android:layout_marginTop="@dimen/dp_40"
android:text="账 户 名"
android:textColor="@color/color_333333"
android:textSize="@dimen/sp_42" />
<EditText
android:id="@+id/et_username"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="42dp"
android:background="@color/color_00000000"
android:gravity="center|left"
android:hint="请输入真实姓名"
android:textColor="@color/color_333333"
android:textSize="@dimen/sp_36" />
</LinearLayout>
S80502-175216.jpg
Screenshot_20180502-175924.png 截屏_20180502_175253.jpg
查看项目打印日志,出现如下异常,归根到底是没有关闭流。okhttp3框架中的Response对象使用后要及时的关闭 response.close()。
A resource was acquired at attached stack trace but never released.
See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'response.body().close()' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:180)
at java.lang.reflect.Method.invoke(Native Method)
at okhttp3.internal.platform.AndroidPlatform$CloseGuard.createAndOpen(AndroidPlatform.java:272)
at okhttp3.internal.platform.AndroidPlatform.getStackTraceForCloseable(AndroidPlatform.java:138)
at okhttp3.RealCall.captureCallStackTrace(RealCall.java:78)
at okhttp3.RealCall.enqueue(RealCall.java:87)
at com.lzy.okgo.cache.policy.BaseCachePolicy.requestNetworkAsync(BaseCachePolicy.java:129)
at com.lzy.okgo.cache.policy.NoCachePolicy$3.run(NoCachePolicy.java:85)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
添加碎片的方式一
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = manager.beginTransaction();
FragmentDiaryReward diaryReward = (FragmentDiaryReward) Fragment.instantiate(this, FragmentDiaryReward.class.getName(), null);
fragmentTransaction.add(R.id.frame_content, diaryReward, diaryReward.getClass().getName());
fragmentTransaction.commit();
视频背景图宽高比计算方法
Glide.with(mContext).load(bean.getShare_cover()).placeholder(R.mipmap.zhanwei3).
listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
if (iv_share_video2 == null) {
return false;
}
if (iv_share_video2.getScaleType() != ImageView.ScaleType.FIT_XY) {
iv_share_video2.setScaleType(ImageView.ScaleType.FIT_XY);
}
ViewGroup.LayoutParams params = iv_share_video2.getLayoutParams();
int vw = iv_share_video2.getWidth() - iv_share_video2.getPaddingLeft() - iv_share_video2.getPaddingRight();
float scale = (float) vw / (float) resource.getIntrinsicWidth();
int vh = Math.round(resource.getIntrinsicHeight() * scale);
params.height = vh + iv_share_video2.getPaddingTop() + iv_share_video2.getPaddingBottom();
iv_share_video2.setLayoutParams(params);
return false;
}
}).into(iv_share_video2);
网友评论