我使用Web服务进行图像处理,它在Postman中运行良好:
现在我想用Dart扑灭http请求:
import 'package:http/http.dart' as http;
static ocr(File image) async {
var url = '${API_URL}ocr';
var bytes = image.readAsBytesSync();
var response = await http.post(
url,
headers:{ "Content-Type":"multipart/form-data" } ,
body: { "lang":"fas" , "image":bytes},
encoding: Encoding.getByName("utf-8")
);
return response.body;
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何上传图像文件,在上面的代码中我得到异常:Bad state: Cannot set the body fields of a Request with content-type "multipart/form-data".
我应该如何编写请求体?
我'com.android.support:support-v4:23.3.0'
在使用我的build.gradle
但是在探索外部库时,我看到了两个版本的support-v4库(23.3.0和24.0.0).如何找到哪个依赖项使用support-v4:24.0.0库?如何强制gradle只添加版本23.3.0?
这是我在build.gradle中的依赖列表:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile ('com.nightonke:wowoviewpager:1.0.2') {
exclude group: 'com.android.support', module:'support-v4'
}
compile ('com.j256.ormlite:ormlite-android:5.0'){
exclude group: 'com.android.support', module:'support-v4'
}
compile files('libs/picasso-2.5.2.jar')
compile files('libs/easyandroidanimationslibrary-v0.5.jar')
compile files('libs/apache-httpcomponents-httpclient.jar')
compile files('libs/apache-httpcomponents-httpcore.jar')
compile 'co.ronash.android:pushe-base:1.2.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile('com.github.ozodrukh:CircularReveal:2.0.1@aar') {
transitive = true;
}
compile files('libs/btsdk.jar')
compile project(':zxing_barcode') // this project include the same version of support-v4 library
compile project(':cropper')// this project include the same version of support-v4 …
Run Code Online (Sandbox Code Playgroud) android gradle android-studio support-v4 gradle-dependencies
我正在开发谷歌扑动的 Android和ios应用程序.
当我添加一个新的依赖就像shared_preferences
到pubspec.yaml
,然后再执行flutter run
在终端,我得到这个错误:
- 出了什么问题:配置项目':shared_preferences'时出现问题.
您尚未接受以下SDK组件的许可协议:[Android SDK Platform 27].
我知道为什么会这样!因为我系统上最新的Android SDK平台是26.它试图下载sdk 27然后失败.没问题!我去了位于这里的图书馆缓存文件夹:
C:\用户\应用程序数据\漫游\酒吧\缓存\主持\ pub.dartlang.org\shared_preferences-0.3.1 \机器人
并编辑build.gradle
文件并更改compileSdkVersion 27
为compileSdkVersion 26
.有用.
到目前为止,我必须为所有新的依赖项执行此操作,
是否有任何方法,例如为所有依赖项定义全局build.gradle文件?所以不需要buil.gradle
单独编辑每个s.
为了获得效果,我扩展了子视图,导致子视图在其父视图的一侧出现.我在子视图中有一个按钮,它在缩放之前有效但在缩放后不起作用.出了什么问题?见下图:
为了缩放孩子我使用这个代码:
childView.bringToFront();
Animation a = new Animation() {
@Override
protected void applyTransformation(float t, Transformation trans) {
float scale = 1f * ( 1 - t ) + SCALE_UP_FACTOR * t;
childView.setScaleX(scale);
childView.setScaleY(scale);
}
@Override
public boolean willChangeBounds() {
return true;
}
};
a.setDuration(ANIM_DURATION);
a.setInterpolator(new Interpolator() {
@Override
public float getInterpolation(float t) {
t -= 1f;
return (t * t * t * t * t) + 1f; // (t-1)^5 + 1
}
});
childView.startAnimation(a);
Run Code Online (Sandbox Code Playgroud)
父母是ViewPager
:
<ViewPager
xmlns:android="http://schemas.android.com/apk/res/android" …
Run Code Online (Sandbox Code Playgroud) 我是 Google flutter sdk 的新手,用于为 Android 和 ios 开发应用程序,
我想加载大图像ListView
,
我想异步加载图像并使用缓存,在 Android JAVA/Kotlin 中我使用 Picasso,我怎样才能获得类似的行为在颤振中?
官方颤振ListView
示例:Flutter 中 ListView 的替代方案是什么
我使用 Google Room 持久性库将数据保存在数据库中。在 Room 中有一个注释(@Embedded):
您可以使用 @Embedded 注释来表示您想要分解为其在表中的子字段的对象。然后,您可以像查询其他单独列一样查询嵌入字段
@Entity
public class MyObject {
// nested class
public class GeneralInfo {
public String ownerName;
@PrimaryKey
public long wellId;
}
@Embedded
public GeneralInfo generalInfo;
public long objectId;
// other fields
}
Run Code Online (Sandbox Code Playgroud)
我使用 Gson 从 REST API 反序列化 json 字符串,我希望 Gson 直接将GeneralInfo
字段反序列化为MyObject
字段。我怎样才能做到这一点?
我希望 GsonMyObject
像这样反序列化 s:
{
objectId : 1
wellId : 1
ownerName : "Me"
}
Run Code Online (Sandbox Code Playgroud)
不是这个
{
generalInfo : {
wellId : 1
ownerName …
Run Code Online (Sandbox Code Playgroud) 我为 a 实现了拖放,RecyclerView
当有一种View
类型时效果很好,RecyclerView
但当有多种视图类型时重置,我在这个 gif 中显示结果:
这是我的代码:
public class RecyclerListAdapter extends RecyclerView.Adapter<ItemViewHolder> {
private final Integer[] INVOICE_ITEMS_LIST = new Integer[]{
INVOICE_DESIGN_TITLE,
INVOICE_DESIGN_TITLE,
INVOICE_DESIGN_LOGO,
INVOICE_DESIGN_TITLE
};
public RecyclerListAdapter() {
mItems.addAll(Arrays.asList(INVOICE_ITEMS_LIST));
}
@Override
public int getItemViewType(int position) {
return INVOICE_ITEMS_LIST[position];
}
@Override
public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
switch (viewType){
case INVOICE_DESIGN_TITLE:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.invoice_design_item_title, parent, false);
break;
case INVOICE_DESIGN_LOGO:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.invoice_design_item_logo, parent, false);
break;
default:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.invoice_design_item_title, parent, false);
}
return …
Run Code Online (Sandbox Code Playgroud) 我使用下面的代码从a截取屏幕截图WebView
.它在Android 6及更低版本中运行良好,但在Android 7中它只占用webview的可见部分.
// before setContentView
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
WebView.enableSlowWholeDocumentDraw();
}
...
// before set webview url
webView.setDrawingCacheEnabled(true);
// after html load complete
final Bitmap b = Bitmap.createBitmap(webView.getMeasuredWidth(),
webView.getContentHeight(), Bitmap.Config.ARGB_8888);
Canvas bitmapHolder = new Canvas(b);
webView.draw(bitmapHolder);
Run Code Online (Sandbox Code Playgroud)
但位图b不完整.如何WebView
在Android Nougat中截取整个屏幕截图?
编辑:
我发现webView.getContentHeight
不行.我对整个webview
高度进行了硬编码,效果很好.问题是:如何WebView
在Android Nougat中获得整体内容高度?
我在AppBarLayout中使用CollapsingToolbarLayout只是因为它在滚动时的视差效果,所以我需要完全折叠布局.我的意思是在向下滚动后将其高度设置为零.我将布局minHeight设置为0dp但不起作用,并且仍然可以看到部分布局.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="40dp"
android:paddingRight="40dp"
android:paddingLeft="40dp"
android:background="#e91e63"
android:fitsSystemWindows="true"
android:minHeight="0dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="0dp"
android:fitsSystemWindows="true"
app:titleEnabled="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/index_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/suitcase"
android:padding="20dp"
android:background="@drawable/index_page_icon_bg"
android:layout_margin="5dp"
app:layout_collapseMode="parallax"/>
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:minHeight="0dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
一般规则:如果您认为这不是一个好的Q,请在评论中声明然后做您喜欢的任何事情!
我在Scaffold
appBar中将一个widget列表作为动作,但是当我按下它们时它们没有响应,我floatingButton
在场景中也有一个并且它完美地工作.
appBar: new AppBar(
title: new Text(
widget.title,
style: new TextStyle(
fontFamily: 'vazir'
),
),
centerTitle: true,
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.search),
highlightColor: Colors.pink,
onPressed: _onSearchButtonPressed(),
),
],
),
void _onSearchButtonPressed() {
print("search button clicked");
}
Run Code Online (Sandbox Code Playgroud)
即使我把IconButton放在一个Row
或Column
小部件中,而不是在其中appBar
,它也不再起作用.
答:
感谢siva Kumar,我在调用函数时遇到了错误,我们应该这样调用它:
onPressed: _onSearchButtonPressed, // without parenthesis.
Run Code Online (Sandbox Code Playgroud)
或者这样:
onPressed: (){
_onSearchButtonPressed();
},
Run Code Online (Sandbox Code Playgroud) 如何找出屏幕尺寸并根据屏幕分辨率放置我的游戏项目?我想在网络客户端上运行我的游戏。
我想调整红色游戏组件的大小,使其适合屏幕并位于中心位置。
LibGdx 对于这个概念有一些很好的 java 类:链接
android ×9
flutter ×6
dart ×3
android-view ×2
ios ×2
android-collapsingtoolbarlayout ×1
android-room ×1
click ×1
flame ×1
gradle ×1
gson ×1
httprequest ×1
java ×1
json ×1
listview ×1
parent-child ×1
picasso ×1
pojo ×1
screensaver ×1
screenshot ×1
support-v4 ×1
webview ×1