我有一个bmp
在Activity1中命名的Bitmap变量,我想将位图发送到Activity2
以下是我用来传递意图的代码.
Intent in1 = new Intent(this, Activity2.class);
in1.putExtra("image",bmp);
startActivity(in1);
Run Code Online (Sandbox Code Playgroud)
在Activity2中,我尝试使用以下代码访问位图
Bundle ex = getIntent().getExtras();
Bitmap bmp2 = ex.getParceable("image");
ImageView result = (ImageView)findViewById(R.Id.imageView1);
result.setImageBitmap(bmp);
Run Code Online (Sandbox Code Playgroud)
应用程序运行时没有例外,但它没有给出预期的结果
我想创建一个可以在安装或删除设备上的其他应用程序时接收广播的应用程序.
我的代码
在表现:
<receiver android:name=".apps.AppListener">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
在AppListener中:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class AppListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
Log.v(TAG, "there is a broadcast");
}
}
Run Code Online (Sandbox Code Playgroud)
但我无法收到任何广播.我认为这个问题是由于应用权限,任何想法?
谢谢你的帮助.
是否可以将RecyclerView锚定到比通常位置稍高的位置,就像大多数可折叠视图上的FAB图标一样(预期结果见图1).
图片1
我尝试了以下代码但它没有给出预期的结果(参见图2了解当前结果)
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="180dp"
android:fitsSystemWindows="true"
app:expanded="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/bannerImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:src="@drawable/starter_screen_bg"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/categories"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:gravity="center"
>
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
图2
添加app:layout_behavior="@string/appbar_scrolling_view_behavior"
将回收器视图附加到可折叠视图,然后忽略添加边距底部.
但是删除它会产生预期的结果,但是滚动视图不会按预期运行(没有视差效果),并且在背景图像滚动后滚动.
因此可以像第一张图像一样实现可折叠视图.
android material-design android-recyclerview android-coordinatorlayout android-collapsingtoolbarlayout
这个问题的主要目的是了解在考虑以下场景的情况下,在开发用于Android开发的PNG和JPG之间选择什么是最佳选择
1)使用jpg图像作为背景是一个很好的选择吗?2)与.png相比,.jpg图像需要更多时间加载吗?3)与.png相比,.jpg会花费更多时间进行渲染/加载吗?
当我们使用png图像时,我已经看到图像大小的巨大差异.
我的.png图像大小之一是4.1 MB,与.jpg图像格式相同的图像大小减少到2.9 MB
需要专家建议.
信息:减少应用程序大小.我仍然使用压缩png压缩图像并压缩jpeg
图像大小差异很大.即.4.1 MB png - >压缩后的2.9 MB jpg减少到654.6 KBs ..
要将图像设置为背景我没有发现任何问题...
在我的Android应用程序中,我使用THREAD_POOL_EXECUTOR使用多个AsyncTask,这使得任务并行运行.有时应用程序挂起.以下是我使用的代码.
如何找到应用程序挂起的点?
new fetchInitialCoinsParallel().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
prefCoinList = getPrefCoin();
if(prefCoinList.size()>0){
for(int i=0;i<prefCoinList.size();i++){
new fetchAltCoinsParallel().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
}
}
public class fetchAltCoinsParallel extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
}
protected String doInBackground(String... params) {
try {
InputStream is = getDataFromURL(params[0]);
if(is!=null){
BufferedReader br = new BufferedReader(new InputStreamReader(is));
synchronized(this){
brList.add(br);
}
}else{
prefCoinNotLoadedTimeOutCount=prefCoinNotLoadedTimeOutCount+1;
}
if(brList.size()==prefCoinList.size()-prefCoinNotLoadedTimeOutCount){
try {
loadAltCoins(getAltCoinDataParallel());
} catch (IOException e) {
e.printStackTrace();
}
maingame.dataReady=true;
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
protected void …
Run Code Online (Sandbox Code Playgroud)我正在使用 v7 支持库。
当我尝试添加以下行 Window.FEATURE_ACTION_BAR_OVERLAY 时,它没有反映在 android 2.3 版上
android android-actionbar android-support-library navigation-drawer
我没有使用 XML 文件来设置波纹可绘制的状态,而是使用 javanew RippleDrawable(color, backgroundDrawable, null)
构造函数,因为我在适配器中使用它,其中每个项目都有自己的颜色。该代码在棒棒糖后设备上按预期工作,但即使我添加了 SDK_INT 检查,它也会在棒棒糖前设备上崩溃并出现以下错误
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
holder.rootView.setBackground(getBackgroundDrawable(ColorConverter.lightenColor(Color.parseColor(item.getTextColor()), 0.6f), background));
}
Run Code Online (Sandbox Code Playgroud)
getBackgroundDrawable()
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static RippleDrawable getBackgroundDrawable(int pressedColor, Drawable backgroundDrawable) {
return new RippleDrawable(getPressedState(pressedColor), backgroundDrawable, null);
}
Run Code Online (Sandbox Code Playgroud)
getPressedState()
private static ColorStateList getPressedState(int pressedColor) {
return new ColorStateList(new int[][]{new int[]{}}, new int[]{pressedColor});
}
Run Code Online (Sandbox Code Playgroud)
错误堆栈跟踪
E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.test.app.adapter.util.DashboardButtonsAdapter.getBackgroundDrawable
12-11 18:40:07.745 14717-14717/com.test.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.test.app, PID: 14717
java.lang.VerifyError: com/test/app/adapter/util/DashboardButtonsAdapter
at com.test.app.fragment.dashboard.DashboardPageFragment.onCreateView(DashboardPageFragment.java:71) …
Run Code Online (Sandbox Code Playgroud) android ×8
performance ×2
android-collapsingtoolbarlayout ×1
bitmap ×1
image ×1
permissions ×1
verifyerror ×1