Questions tagged «android»

Android是Google的移动操作系统,用于对数字设备(智能手机,平板电脑,汽车,电视,Wear,Glass和IoT)进行编程或开发。对于与Android相关的主题,请使用特定于Android的标签,例如android-intent,android-activity,android-adapter等。对于与开发或编程无关但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。

20
带CameraUpdateFactory.newLatLngBounds的moveCamera崩溃
我正在使用新的Android Google Maps API。 我创建一个包含MapFragment的活动。在活动中,onResume我将标记设置到GoogleMap对象中,然后为包含所有标记的地图定义了一个边界框。 这使用以下伪代码: LatLngBounds.Builder builder = new LatLngBounds.Builder(); while(data) { LatLng latlng = getPosition(); builder.include(latlng); } CameraUpdate cameraUpdate = CameraUpdateFactory .newLatLngBounds(builder.build(), 10); map.moveCamera(cameraUpdate); 的调用map.moveCamera()导致我的应用程序崩溃,并带有以下堆栈: Caused by: java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet at maps.am.r.b(Unknown Source) at maps.y.q.a(Unknown Source) at maps.y.au.a(Unknown …

7
Android Studio单元测试:读取数据(输入)文件
在单元测试中,如何在不对路径进行硬编码的情况下从(桌面)文件系统上的json文件读取数据? 我想从文件中读取测试输入(用于我的解析方法),而不是创建静态字符串。 该文件与我的单元测试代码位于同一位置,但是如果需要,我也可以将其放置在项目中的其他位置。我正在使用Android Studio。

12
如何在Android应用程序中单击按钮以打开第二个活动
我正在学习构建android应用程序,我需要一些具体帮助。我似乎无法确定需要更改哪些模板代码位,以及哪些位是静态的。 在LAYOUT文件夹中,我的ACTIVITY_MAIN.XML内容如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/main_buttons_photos" /> </LinearLayout> 接下来,我有我的第二个活动ACTIVITY_SEND_PHOTOS.XML这是 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" tools:context=".SendPhotos" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/title_activity_send_photos" android:textAppearance="?android:attr/textAppearanceLarge" /> </RelativeLayout> 然后,我有了MainActivity.java(这是.class吗?),它读取了com.example.assent.bc包; import android.os.Bundle; import android.app.Activity; import …


1
Android SQLite:insert / replace方法中的nullColumnHack参数
Android SDK提供了一些使用SQLite操纵数据的便捷方法。但是插入和替换方法都使用一些nullColumnHack我不理解的参数。 该文档通过以下内容对此进行了解释,但是如果一个表具有多个允许的列NULL怎么办?我真的不明白:/ SQL不允许插入完全空的行,因此,如果initialValues为空,则此列[ / row for replace ]将被明确分配一个NULL值。
96 android  sqlite 


4
如何在Retrofit 2.0中使用拦截器添加标题?
我们的团队决定采用Retrofit 2.0,而我正在对此进行一些初步研究。我是这个图书馆的新手。 我想知道如何interceptor通过Android应用程序中的Retrofits 2.0添加自定义标题。有很多关于在Retrofit 1.X中使用添加标头的教程interceptor,但是由于API在最新版本中发生了很大变化,因此我不确定如何在新版本中适应这些方法。另外,Retrofit尚未更新其新文档。 例如,在以下代码中,应如何实现Interceptor该类以添加额外的标头?此外,未记录的Chain对象到底是什么?何时会intercept()被调用? OkHttpClient client = new OkHttpClient(); client.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Response response = chain.proceed(chain.request()); // How to add extra headers? return response; } }); Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_API_URL) .client(client) .addConverterFactory(GsonConverterFactory.create()) .build();
96 java  android  retrofit 

7
Android SQLite DB何时关闭
我正在使用android上的SQLite数据库。我的数据库管理器是一个单例,现在在初始化时打开与数据库的连接。确保数据库始终处于打开状态是安全的,这样当有人调用我的班级来使用数据库时,该数据库已经打开了吗?还是应该在每次访问之前和之后打开和关闭数据库。始终保持打开状态是否有害? 谢谢!
96 android  sqlite 

11
嵌套Scrollview滚动中的Recyclerview滚动,但不能像普通Recyclerview或Nested Scrollview一样快速滚动
我正在使用RecyclerView内部NestedScrollView,并且有效。但是当我RecyclerView在内部LinearLayout或其他物体上使用时,它会根据手势以各种速度滚动。滚动倾听手势,如果我仅向上滑动一点,则滚动一点;而如果我非常快速地滑动,则滚动非常快。现在我的问题是RecyclerView内部NestedScrollView肯定滚动但快速滚动不起作用。但是,我快或慢滑动,RecyclerView或NestedScrollView只滚动一点。 如何使我NestedScrollView或RecyclerView该滚动视图内部以各种速度滚动?

25
状态栏变为白色,并且在其后面不显示内容
我正在棉花糖上试用AppCompat。我想有一个透明的状态栏,但是它变成白色。我尝试了几种解决方案,但它们对我不起作用(透明状态栏不适用于windowTranslucentNavigation =“ false”,Lollipop:在statusBar后面绘制,其颜色设置为transparent)。这是相关的代码。 我的styles.xml <style name="Bacon" parent="Theme.Bacon"/> <style name="Theme.Bacon" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/theme_primary</item> <item name="colorPrimaryDark">@color/theme_primary_dark</item> <item name="colorAccent">@color/theme_accent</item> <item name="windowActionBar">false</item> <item name="windowActionBarOverlay">true</item> <item name="windowNoTitle">true</item> <item name="android:windowBackground">@color/background_material_light</item> </style> <style name="Theme.Bacon.Detail" parent="Bacon"/> v21 <style name="Bacon" parent="Theme.Bacon"> <item name="android:windowDrawsSystemBarBackgrounds">true</item> </style> <style name="Theme.Bacon.Detail" parent="Bacon"> <item name="android:statusBarColor">@android:color/transparent</item> </style> 活动 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" …

12
在RecyclerView中刷新数据并保持其滚动位置
如何刷新显示在RecyclerView(调用notifyDataSetChanged其适配器的)中的数据,并确保将滚动位置重置为准确的位置? 如果情况良好,ListView则只需检索getChildAt(0),检查其内容getTop()并setSelectionFromTop随后使用相同的准确数据进行调用。 在的情况下,似乎不可能RecyclerView。 我猜我应该使用LayoutManager确实提供了它的它scrollToPositionWithOffset(int position, int offset),但是检索位置和偏移量的正确方法是什么? layoutManager.findFirstVisibleItemPosition()和layoutManager.getChildAt(0).getTop()? 还是有一种更优雅的方式来完成工作?

5
如何从可绘制对象引用样式属性?
我想为我的应用程序选择2个主题。为了做到这一点,我定义了一些属性,如下所示: <attr format="color" name="item_background" /> 然后,我创建了两个主题,如下所示: <style name="ThemeA"> <item name="item_background">#123456</item> </style> <style name="ThemeB"> <item name="item_background">#ABCDEF</item> </style> 这种方法效果很好,使我可以轻松创建和修改多个主题。问题在于,它似乎只能在Views中使用,而不能在Drawables中使用。 例如,从布局内的View引用值可以工作: <TextView android:background="?item_background" /> 但是在Drawable中执行相同操作不会: <shape android:shape="rectangle"> <solid android:color="?item_background" /> </shape> 运行应用程序时出现此错误: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 如果不是?item_background我使用硬编码颜色,而是可以使用它,但是那不允许我使用主题。我也尝试过?attr:item_background,但同样发生。 我该怎么办?为什么在Views中却不能在Drawables中使用呢?我在文档的任何地方都找不到此限制...

9
如何传递包含对象列表的可包裹对象?
我在Parcelable下面创建了一个对象,我的对象包含一个List产品。在我的构造函数中,如何处理Parcelablefor的重新创建List? 我已经检查了包裹中所有可用的方法,所有可用的方法是readArrayList(ClassLoader)。我不确定这是否是最好的方法,您的建议是否会受到赞赏。 public class Outfits implements Parcelable { private String url; private String name; private List<Product> products; public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getName() { return name; } public void setName(String name) { this.name = name; } public …

29
数据绑定类未生成
我使用的数据在我的项目绑定,使用时<layout>和<data>在我的XML绑定类不产生。 例如我有activity_main.xml <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> </data> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> </RelativeLayout> </layout> 现在,如果我ActivityMainBinding在活动/片段中书写,则会显示错误,表明该类不可用。但是在将其包含<variable>在我的xml文件中之后,它能够生成ActivityMainBinding类。 Android Studio:2.1.3 类路径:com.android.tools.build : gradle : 2.1.3 minSdkVersion 16 targetSdkVersion 24 buildToolsVersion 24.0.0


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.