我想知道该clipToPadding
属性ViewGroup
在Android中的作用是什么?
我一直在浏览文档和一些网站,但我没有遇到任何实际解释它的作用和含义,没有我能真正理解的,所以我认为在这里问它可能是个好主意.
嗨我想从我的工具栏中删除API 21及更高版本的高程和阴影效果.以下是我的尝试
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setElevation(0);
Run Code Online (Sandbox Code Playgroud)
我的XML工具栏.我试图将高程设置为0dp
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:elevation="0dp"
android:theme="@style/ToolbarStyle"
app:theme="@style/ToolbarStyle"
>
Run Code Online (Sandbox Code Playgroud)
如果有帮助的话,这就是ToolbarStyle
<style name="ToolbarStyle" parent="ThemeOverlay.AppCompat.Dark">
<item name="colorControlNormal">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
编辑1:在样式v21中尝试以下操作.还是一样的结果
<style name="ToolbarStyle" parent="ThemeOverlay.AppCompat.Dark">
<item name="colorControlNormal">@android:color/white</item>
<item name="android:elevation">0dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
编辑2:工具栏在我的布局中
android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/toolbar" />
Run Code Online (Sandbox Code Playgroud) 我的应用程序包含一个Activity
用户Fragments
.
我希望使用Espresso来测试用户界面Fragments
.但是我遇到了一个问题.
如何测试一个Fragment
未添加到Activity
在onCreate
.我见过的所有例子都Fragments
涉及到Fragment
被添加onCreate
.那么我怎么能告诉Espresso去特定的Fragment
并从那里开始呢?
谢谢
介绍
在我的应用程序中,我希望获得用户当前所在位置的一次性准确位置.当我FusedLocationProviderApi.getLastLocation
有时使用时,这将是null或过时的位置,因为我发现这只是一个缓存的位置,并没有请求新的位置更新.
解决方案是仅请求位置更新一次,如下所示.
LocationRequest locationRequest = LocationRequest.create()
.setNumUpdates(1)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(0);
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,locationRequest,this)
Run Code Online (Sandbox Code Playgroud)
现在我总是得到一个更准确的位置.
我的问题
如何确定位置更新是否失败?因为我只要求1.
获取位置更新时,将调用此回调
@Override
public void onLocationChanged(Location location) {
}
Run Code Online (Sandbox Code Playgroud)
但是,如果位置更新失败,则不会调用此方法.
我试过了什么
我看到有一个ResultCallback.但是,即使一次性位置更新失败,也始终会调用onSuccess.
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,locationRequest,this).setResultCallback(new ResultCallbacks<Status>() {
@Override
public void onSuccess(@NonNull Status status) {
DebugUtils.log("requestLocationUpdates ResultCallback onSuccess + " + status.toString(),true,true);
}
@Override
public void onFailure(@NonNull Status status) {
DebugUtils.log("requestLocationUpdates ResultCallback onFailure + " + status.toString(),true,true);
}
});
Run Code Online (Sandbox Code Playgroud)
其他
运用 com.google.android.gms:play-services-location:8.4.0
感谢您的阅读,请帮帮我.
我正在学习自定义视图,并希望了解invalidate()
和requestLayout()
.
请参考这个答案及其图表:
invalidate()
告诉Android视图的状态已经改变,需要重新绘制.
requestLayout()
表示视图的大小可能已更改,需要重新测量,然后重新绘制.
invalidate()
将调用dispatchDraw()
,draw()
并onDraw()
因此重新呈现视图.
requestLayout()
另一方面,从测量再到再次渲染,几乎可以做任何事情.
为什么那么多的例子(甚至是TextView
源代码)都会调用invalidate()
,然后requestLayout()
就在下一行呢?
我得到一些包含一些食物菜单项的JSON数据
请注意:这只是一个示例,有时会有超过2个图像,阵列中还有更多菜单项!
{
"menu": [
{
"url": "/api/v1/menu/1",
"name": "Best Food",
"description": "really nice food",
"opening_time": "every day from 9am to 6pm",
"contact_email": "info@food.com",
"tel_number": "+54 911 3429 5762",
"website": "http://bestfood.com",
"images": [
{
"url": "https://blahblah/image1.jpg"
},
{
"url": "https://blahblah/image2.jpg"
}
]
},
]
}
Run Code Online (Sandbox Code Playgroud)
每个项目都有一些信息和一组图像URL.
我正在使用Glide图像库来处理这些图像,并使用Retrofit 2.0从端点下载JSON数据.一切都很顺利.
但是,我需要存储此下载的数据以供离线访问.
目前,我在现有模型上使用ORM Lite将所有JSON数据存储在数据库中.这部分还可以.
但是,在我的数据库中,我只存储图像URL,因为我被告知在数据库中存储图像(作为blob)不是好方法.
因此,我的应用程序中有一个部分可以查看已保存的菜单,如果用户选择,可以选择将其下载以供脱机访问.
此时值得一提的是,我已经在数据库中拥有原始菜单信息,因为用户必须首先查看菜单才能在DB中获取它.
但问题是图像.
这是我不知道如何进行的地方,但我列出了我正在考虑的解决方案和问题,并希望人们可以告诉我什么是最好的行动方案.
使用服务下载图像.我认为这是强制性的,因为我不知道将有多少图像,即使用户退出应用程序,我也希望继续下载
Glide有一个仅下载图像选项,您可以在此处和此处阅读其配置缓存所在的位置(内部私有或外部公共).问题是我对设置缓存大小感到不舒服,因为我不知道需要什么.我想设置无限.
我需要能够删除保存的菜单数据,特别是如果它保存在外部公共目录中,因为在删除应用程序时不会删除该菜单数据,或者如果用户选择从应用程序中删除已保存的菜单.我以为我可以将文件图像URI或整个保存菜单的位置存储在数据库中,但不确定这是否是一种好方法
我在不同的来源和答案中读到,在这个用例中只是将图像缓存到SD卡等,我应该专门使用网络库来避免将位图分配给堆内存.我目前在我的应用程序中使用OK HTTP.
我通过这样做在我的Retrofit适配器中设置了一个全局超时
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setReadTimeout(20, TimeUnit.SECONDS);
okHttpClient.setConnectTimeout(20, TimeUnit.SECONDS);
retrofit = new Retrofit.Builder()
.client(okHttpClient)
.build();
Run Code Online (Sandbox Code Playgroud)
大!但是我想为某些请求设置特定的超时时间
public interface MyAPI {
@GET()
Call<Void> notImportant (@Url String url);
@GET
Call<Void> veryImportant(@Url String url);
Run Code Online (Sandbox Code Playgroud)
所以veryImportant
调用我想要超时35秒,但notImportant
默认
这可能吗?
我的研究结果不尽如人意.
我遇到过这个,但不确定它是否适用于Retrofit
https://github.com/square/okhttp/wiki/Recipes#per-call-configuration
谢谢你的阅读.请帮忙.
您好我的自定义视图:
MyCustomView extends View
Run Code Online (Sandbox Code Playgroud)
我做了一个VectorDrawable
mMyVectorDrawable = VectorDrawableCompat.create(getContext().getResources(), R.drawable.ic_some_image, null);
Run Code Online (Sandbox Code Playgroud)
我已经设定了界限
mMyVectorDrawable.setBounds(0, 0, mMyVectorDrawable.getIntrinsicWidth(), mMyVectorDrawable.getIntrinsicHeight());
Run Code Online (Sandbox Code Playgroud)
我在画布上绘制它
mMyVectorDrawable.draw(canvas);
Run Code Online (Sandbox Code Playgroud)
我在0,0位置看到了图像
但我该如何定位呢?如何定位Rect,我认为前两个参数setBounds
将是X和Y坐标的开始绘图,但这只会影响尺寸.
如何将矢量绘图放在画布上?
谢谢阅读
我正在使用这样的格式化货币字符串获取一些JSON数据
?35
Run Code Online (Sandbox Code Playgroud)
但是,我注意到在Nexus 5(Lollipop)上它显示正确,但其他手机,如HTC one mini和Samsung GT-I9505,它显示一个空白字符.
我试图研究这个问题,除了在XML布局文件中,我找不到解决方案,确保该行存在
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
但我仍然有同样的问题
请帮忙
编辑2015年5月15日
加载自定义字体NotoSans(请注意我知道这会泄漏内存,但它只是一个快速测试)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView ruble = (TextView)findViewById(R.id.ruble);
Typeface myFont = Typeface.createFromAsset(getAssets(),"fonts/NotoSans-Regular.ttf");
ruble.setTypeface(myFont);
}
Run Code Online (Sandbox Code Playgroud)
strings.xml中定义的俄罗斯卢布符号(注意我尝试了所有)
<string name="rubleSymbolJava">\u20BD</string>
<string name="rubleSymbolHTML">₽</string>
<string name="rubleSymbolHTMLHex">₽</string>
Run Code Online (Sandbox Code Playgroud)
同样的问题,在老式手机上显示为方形但适用于Android 5.0但没有更旧.
已解决请参阅我的回答
你好,我想说我有一个包含以下内容的布局
<ScrollView
android:id="@+id/scroll"
android:layout_below="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="240dp"
android:scaleType="centerCrop"
android:src="@drawable/android" />
<View android:id="@+id/anchor"
android:layout_width="match_parent"
android:layout_height="240dp" />
<TextView
android:id="@+id/body"
android:layout_below="@+id/anchor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:textColor="@android:color/black"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:text="@string/sample" />
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
是否可以使用协调器布局使图像视图在向上或向下滚动时以滚动视图速度的一半移动.
android ×10
java ×2
android-view ×1
caching ×1
google-maps ×1
json ×1
okhttp ×1
okhttp3 ×1
retrofit ×1
retrofit2 ×1