我正在开发一个增强现实应用程序,其中我有一个摄像头预览屏幕,我在其上绘制了一些相对于设备移动而移动的标记.
当我lock and unlock在设备上时,标记会冻结并且不会进一步移动.我无法找到发生这种情况的原因.这有什么可行的解决办法吗?任何帮助将不胜感激.
我的SurfaceView类:
public class CameraSurface extends SurfaceView implements SurfaceHolder.Callback
{
private static SurfaceHolder holder = null;
public static Camera camera = null;
Activity ctx;
public CameraSurface(Activity context) {
super(context);
ctx=context;
try {
holder = getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public CameraSurface(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CameraSurface(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
if …Run Code Online (Sandbox Code Playgroud) 我想实现流媒体视频列表应用.我用a RecyclerView来显示我的列表项.项目类型包括4种类型:文章,状态,照片和视频.我们应该只关注视频类型.这是我的RecyclerView适配器的代码:
public class FollowedPostAdapter extends RecyclerView.Adapter implements OnFollowTagCallback, OnLikeCallback {
private Context context;
private List<PostItem> newsFeedList;
public RecyclerView recyclerView;
public LinearLayoutManager linearLayoutManager;
private HashMap<Integer, DemoPlayer> playerList;
private int visibleThreshold = 5;
// private int previousTotal = 0;
private int visibleItemCount, firstVisibleItem, totalItemCount;
private boolean loading;
private OnRecyclerViewLoadMoreListener loadMoreListener;
private final String text_comment;
private final String mReadMoreHtml;
private long userId;
public FollowedPostAdapter(Context context, RecyclerView recyclerView, List<PostItem> newsFeedList) {
this.context = context;
playerList = new HashMap<>();
this.newsFeedList = newsFeedList;
this.recyclerView …Run Code Online (Sandbox Code Playgroud) 我有一个ViewPager ,Fragment如果某个动作发生,我必须更换第一个.
public static class PagerAdapter extends FragmentStatePagerAdapter{
private TempChannel latestChannel;
private VideosFragment.SortType sortType;
public PagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
if(latestChannel == null) {
return new LatestVideosFragment();
}else{
return VideosFragment.getVideosFragment(latestChannel, sortType);
}
case 1:
return new LiveVideosFragment();
case 2:
return new ConversationsFragment();
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,当我单击某个通道时LatestVideosFragment,适配器中的第一个位置应该更改为VideosFragment该类的实例.
public void startLatestChannelFragment(TempChannel channel, VideosFragment.SortType sortType){
adapter.setLatestChannel(channel, sortType);
adapter.notifyDataSetChanged();
Log.d("x", "on channel started");
}
Run Code Online (Sandbox Code Playgroud)
我假设调用 …
我正在按照本教程ViewPager在我的项目中实现.我已成功使用静态图像.现在我想更改它,以便从网址中检索图像并显示在其中ViewPager.以下是我的代码.
我应该在哪里添加下载图像的方法以及如何将其设置为我的
ViewPager?
任何帮助将不胜感激.
主要活动:
public class MainActivity extends AppCompatActivity {
private ArrayList<Integer> images;
private BitmapFactory.Options options;
private ViewPager viewPager;
private View btnNext, btnPrev;
private FragmentStatePagerAdapter adapter;
private LinearLayout thumbnailsContainer;
private final static int[] resourceIDs = new int[]{R.mipmap.a, R.mipmap.b,
R.mipmap.c, R.mipmap.d, R.mipmap.e, R.mipmap.f, R.mipmap.g};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
images = new ArrayList<>();
//find view by id
viewPager = (ViewPager) findViewById(R.id.view_pager);
thumbnailsContainer = (LinearLayout) findViewById(R.id.container);
btnNext = …Run Code Online (Sandbox Code Playgroud) 我使用Picasso库在我的应用程序中加载图像.但在某些图像中,它显示了一个彩色的角落.看到附加图像中的红色.有谁知道为什么会这样?如何解决这个问题?
码:
Picasso picasso = Picasso.with(getActivity());
picasso.setDebugging(true);
picasso.load(downloadPath+imgDetailPhoto)
.placeholder(R.drawable.no_image)
.error(R.drawable.no_image)
.into(eventImage, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Log.d("Error...", "picasso load error");
Picasso.with(getActivity()).load(R.drawable.no_image).into(eventImage);
}
});
Run Code Online (Sandbox Code Playgroud) 我想以SeekBar编程方式在画布上绘制.我编写了代码来设置SeekBar基于设备密度的LayoutParams .我正在使用具有设备密度的开关盒
final DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
if(metrics.densityDpi <= DisplayMetrics.DENSITY_LOW){
zoomBarParams = new LinearLayout.LayoutParams(18,
LayoutParams.FILL_PARENT);
} else if (metrics.densityDpi <= DisplayMetrics.DENSITY_MEDIUM){
zoomBarParams = new LinearLayout.LayoutParams(24,
LayoutParams.FILL_PARENT);
}else if (metrics.densityDpi <= DisplayMetrics.DENSITY_HIGH){
zoomBarParams = new LinearLayout.LayoutParams(24,
LayoutParams.FILL_PARENT);
}else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XHIGH){
zoomBarParams = new LinearLayout.LayoutParams(31,
LayoutParams.FILL_PARENT);
}else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXHIGH){
zoomBarParams = new LinearLayout.LayoutParams(60,
LayoutParams.FILL_PARENT);
}else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXXHIGH){
zoomBarParams = new LinearLayout.LayoutParams(60,
LayoutParams.FILL_PARENT);
} else {
zoomBarParams = new LinearLayout.LayoutParams(60,
LayoutParams.FILL_PARENT);
}
Run Code Online (Sandbox Code Playgroud)
但这不适用于三星Note …
如果ListView只显示5个项目,则所有数据为40个项目.如何获得当前选择的可见项目(1~5)中的哪个位置?我已经尝试 getSelectedItemPosition但它将返回所有数据中的位置.我想在每个项目上显示可见项目中的位置编号.
class MyAdapter extends BaseAdapter {
@Override
public int getCount(){
...
}
@Override
public Object getItem(int position){
...
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// I want to get the position number in visible items here
}
}
Run Code Online (Sandbox Code Playgroud) 我需要创建一个应用程序,我想录制视频,并在文件大小超过10 mb时停止录制.这可能吗?我知道保存后可以检查文件大小.但我想知道这是否可以在运行时完成.任何帮助将不胜感激.
我有一个RecyclerView用于显示使用内容提供程序从内容提供程序获取的数据LoaderManager.它工作正常,但我注意到加载大数据时我的下面的实现有一些性能问题,显示数据有一个滞后,因为我使用a ViewPager加载Fragment主机这个方法
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
Favorites = new ArrayList<>();
if (cursor != null) {
while (cursor.moveToNext())
Favorites.add(FavoritesModel.fromCursor(cursor));
}
adapter = new FavoritesAdapter(getActivity(),Favorites);
favoritesRecyclerView.setAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)
所以我选择做以下事情:
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
........
adapter = new FavoritesAdapter(getActivity(),Favorites);
favoritesRecyclerView.setAdapter(adapter);
........
Run Code Online (Sandbox Code Playgroud)
然后在onLoadFinished上
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
Favorites = new ArrayList<>();
if (cursor != null) {
while (cursor.moveToNext())
Favorites.add(FavoritesModel.fromCursor(cursor));
}
adapter.notifyDataSetChanged();
}
Run Code Online (Sandbox Code Playgroud)
使用此功能无需显示.什么是问题,因为onLoadFinished总是被调用,我知道它始终在UI线程上调用
我想我的应用程序打开一些网址.但不是所有的.Android不允许排除网址((通过使用android:pathPattern或android:pathPrefix.
现在打开我使用的网址:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(PRIVACY_POLICY_URL));
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(browserIntent);
Run Code Online (Sandbox Code Playgroud)
我想只在外部浏览器中打开一些网页链接.可能吗?
我想将某些URL中的图像动态添加到线性布局中.运行该段代码时出现错误无法启动活动
ComponentInfo:位于com.example的com.example.star.example.CompampleActivity.insertPhoto(CompinfoActivity.java:50)的com.example.star.example.CompinfoActivity.getBitmapFromURL(CompinfoActivity.java:70)中的android.os.NetworkOnMainThreadException. star.example.CompinfoActivity.onCreate(CompinfoActivity.java:38)
请帮忙.这是我下面活动的代码.
public class CompinfoActivity extends AppCompatActivity {
Dialog dialog;
LinearLayout myGallery;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compinfo);
dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity_compinfopopup);
dialog.getWindow().getAttributes().width = AbsListView.LayoutParams.MATCH_PARENT;
dialog.getWindow().getAttributes().height = AbsListView.LayoutParams.WRAP_CONTENT;
dialog.show();
myGallery = (LinearLayout) dialog.findViewById(R.id.mygallery);
myGallery.addView(insertPhoto("http://example.com/a.png"));
myGallery.addView(insertPhoto("http://example.com/b.png"));
myGallery.addView(insertPhoto("http://example.com/c.png"));
myGallery.addView(insertPhoto("http://example.com/d.png"));
new MyTask().execute();
}
View insertPhoto(String path){
Bitmap bm;
bm = getBitmapFromURL(path);
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setLayoutParams(new AbsListView.LayoutParams(250, 250));
layout.setGravity(Gravity.CENTER);
ImageView imageView = new ImageView(getApplicationContext());
imageView.setLayoutParams(new AbsListView.LayoutParams(220, 220));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageBitmap(bm);
layout.addView(imageView);
return layout;
}
public static Bitmap …Run Code Online (Sandbox Code Playgroud) 我在Android项目中使用以下代码下载文件:
URL url = new URL(fileUrl);
URLConnection conection= url.openConnection();
conection.setDoOutput(true);
conection.connect();
int lenghtOfFile = conection.getContentLength();
Run Code Online (Sandbox Code Playgroud)
如果fileUrl是apk,则lenghtOfFile始终返回-1.
但如果是图像,视频类型,... lenghtOfFile返回正好.
为什么?
我正在使用eclipse,Android SDK修订版23.
我想将另一个类的数据添加到我的数据库中,我得到这个错误:
"SQLiteLog:(1)接近"Produse":语法错误"和"SQLiteDatabase:错误插入高级成衣= 102.0 Ingrediente =成分1;成分2;成分3;组分4;成分5; Nume Produse = Produsul 15波萨= poza15.jpg Gramaj = 195.0
android.database.sqlite.SQLiteException:邻近"Produse":语法错误(码1):在编译:INSERT INTO Produse(高级成衣,Ingrediente,Nume Produse,波萨,Gramaj)VALUES(,,,??? ?,?)"
这是我的MyDBHandler类的代码
public class MyDBHander extends SQLiteOpenHelper{
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "produseDB.db";
public static final String TABLE_PRODUCTS = "Produse";
public static int COLUMN_ID = 0;
public static String COLUMN_PRODUS = "Nume Produse";
public static String COLUMN_INGREDIENTE = "Ingrediente";
public static String COLUMN_GRAMAJ = "Gramaj";
public static String COLUMN_PRET = "Pret";
public static String …Run Code Online (Sandbox Code Playgroud)