使用OkHttp我们可以发出HTTP请求然后从服务器获得响应
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
Run Code Online (Sandbox Code Playgroud)
然后用Gson lib将响应转换为我们需要的对象.
这是来自Square/OkHttp doc:
它的请求/响应API设计具有流畅的构建器和不变性.它支持同步阻塞调用和带回调的异步调用
我从stackOverFlow中读取
如果可用,Retrofit会自动使用OkHTTP
.
所以我的问题是究竟是什么改造?
什么改造可以做到OkHttp不能?!
我认为OkHttp和Gson解决了请求API问题,那么Retrofit为我们解决了什么问题?
我将FloatingActionButton设置为屏幕底部,我想为按钮设置动画.
就像谷歌在他们的Google+应用中实现它一样.
我认为需要CoordinatorLayout和AppBarLayout但是如何实现它以将它与FloatingActionButton一起使用?
android android-animation material-design floating-action-button android-design-library
我有两个垂直StackView
嵌套在水平StackView
.
对于第一个:
titlesView.axis = .vertical
titlesView.distribution = .fill
titlesView.alignment = .leading
Run Code Online (Sandbox Code Playgroud)
第二个:
checkView.axis = .vertical
checkView.distribution = .fil
checkView.alignment = .center
Run Code Online (Sandbox Code Playgroud)
和 holderStackView(root)
holderStackView.axis = .horizontal
holderStackView.alignment = .center
holderStackView.distribution = .fill
holderStackView.addArrangedSubview(titlesView)
holderStackView.addArrangedSubview(checkView)
titlesView.setContentHuggingPriority(.defaultLow, for: .horizontal)
checkView.setContentHuggingPriority(.defaultHigh, for: .horizontal)
Run Code Online (Sandbox Code Playgroud)
我希望 titlesView 必须填充 StackView,但 checkView StackView 填充 holderStackView 堆栈视图。
如果我为它们center
或设置对齐leading
,那么它会按预期工作并且第一个会增长。
期待:
现实:
我该如何解决这个问题?
它仅发生在 的contentView
中UITableViewCell
,请参阅下面的最小示例:
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.separatorColor = UIColor(red:0.87, green:0.87, …
Run Code Online (Sandbox Code Playgroud) 在android doc https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html#setColorSchemeColors(int ...)
中设置颜色架构有三种方法
,3种方法有什么区别?
setColorScheme(int... colors)
setColorSchemeColors(int... colors)
setColorSchemeResources(int... colorResIds)
Run Code Online (Sandbox Code Playgroud) 我想通过Retrofit将json对象发送到服务器作为RequestBody
{"attach": {
"image": {
"height": 1473,
"urlRef": "",
"width": 1473
},
"video": {
"duration": "4.365",
"height": 1920,
"thumbUrl": "",
"urlRef": "",
"width": 1080
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的改造对象
Retrofit.Builder retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create());
Run Code Online (Sandbox Code Playgroud)
这是我的改造界面:
@Multipart
@POST("post/")
Observable<Response> postAttach(
@Part("attach") RequestBody asset
, @Part MultipartBody.Part attachment
);
Run Code Online (Sandbox Code Playgroud)
并创建RequestBody如下:
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), gson.toJson(myAttach));
Run Code Online (Sandbox Code Playgroud)
但是这个请求发送json作为字符串而不是json对象
那我怎么发送jsonObejct?
注意:如果我使用@Body发送作为json对象,但我不能将@Body与@MultiPart一起使用!
因为RecyclerView
如果它没有任何项目,则单击RecyclerView
有效,但如果它有项目,则单击RecyclerView
不起作用。小心我的意思是点击 just RecyclerView
notRecyclerView
的项目
recyclerView.setOnClickListener(view -> {Timber.d("recyclerView clicked");});
Run Code Online (Sandbox Code Playgroud)
RecyclerView
即使上面有项目,我如何设置可点击。
android view android-layout android-view android-recyclerview
android ×5
java ×2
android-view ×1
autolayout ×1
ios ×1
okhttp ×1
okhttp3 ×1
retrofit ×1
retrofit2 ×1
swift ×1
uistackview ×1
uitableview ×1
view ×1