按钮并排LinearLayout(Button side by side LinearLayout)
大家好,我正在尝试将按钮并排,但我似乎无法让它工作。 我真的试过搞乱并尝试谷歌但失败了。
<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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity" android:orientation="vertical" android:weightSum="1"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Name" android:id="@+id/name" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/nameText" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" android:layout_gravity="right" />
我怎么会这样做?
Hello guys I am trying to make the buttons side by side but I cant seem to get it work. I really tried messing around and tried google but failed.
<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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity" android:orientation="vertical" android:weightSum="1"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Name" android:id="@+id/name" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/nameText" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" android:layout_gravity="right" />
How would I do it guys?
原文:
更新时间:2022-08-01 09:08
最满意答案
你需要序列化你的params字典,然后对它进行字符串编码,因为你的body参数中有一个JSON对象。 试试这个:
NSDictionary *params = @{@"email": @"email@gmail.com", @"name": @"myName"}; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:nil]; NSString *json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; NSDictionary *dict = @{@"body":json}; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; [manager POST:@"http://myURL.com/user" parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSString *myString = [[NSString alloc] initWithData:operation.request.HTTPBody encoding:NSUTF8StringEncoding]; NSLog(@"Error: %@", myString); }];
You need to serialize your params dictionary and then string encode it, since your body parameter has a JSON object in it. Try using this :
NSDictionary *params = @{@"email": @"email@gmail.com", @"name": @"myName"}; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:nil]; NSString *json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; NSDictionary *dict = @{@"body":json}; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; [manager POST:@"http://myURL.com/user" parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSString *myString = [[NSString alloc] initWithData:operation.request.HTTPBody encoding:NSUTF8StringEncoding]; NSLog(@"Error: %@", myString); }];
相关问答
更多-
你面临的问题是你看错了地方。 正如你所说的,你正在使用AFNetworking的POST方法来发布数据。 强调POST。 GET和POST是两个完全不同的东西。 GET用于检索存储在url中的值,例如www.example.com/example-get.php?key1=value1&key2=value2 。 您可以通过执行$_GET['key1']访问PHP中的不同值。 POST是不同的。 这与HTTP消息正文一起发送,并且不能在浏览历史记录或url中看到。 你可以通过使用$_POST['family ...
-
我已经弄清楚了。 这是从文本字段和UIImageVIew发布图像和文本: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json",nil]; manager.responseSerializ ...
-
过程如下: 使用userName , userEmail和userPassword参数创建字典。 NSDictionary *params = @{@"userName" : @"rob", @"userEmail" : @"rob@email.com", @"userPassword" : @"password"}; 确定图像的路径: NSString *path = [[NSBundle ...
-
你必须将路径数组作为参数@ {@“data”:@ [params]} NSDictionary *foo = @{ @"id" : @"2011011", @"request" : @"single", @"gender" : @"M", @"username" : @"name", }; ...
-
您正在使用一种复杂的方法来构建操作,但它会起作用。 但它应该工作,你缺少的是分配XMLparser。 在AFXMLRequestOperation的文档中说明。 NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"http://myPath/Iphone/method" parameters:params]; AFXMLRequestOperation *operation = [[AFXMLReques ...
-
您遇到的问题是因为您正在实例化AFJSONRequestOperation,默认情况下需要一个JSON友好的响应类型。 您是否期待JSON响应? 如果没有,您应该使用一个不太具体的Request类。 例如,您可以使用HTTPRequestOperationWithRequest :. NSURL *url = [NSURL URLWithString:@"http://dev.url"]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBa ...
-
AFNetworking 3.0用于上传图像错误的多部分表单数据(AFNetworking 3.0 Multipart form data for uploading image error)[2023-07-15]
使用此方法 -(void)callWebserviceToUploadImageWithParams:(NSMutableDictionary *)_params imgParams:(NSMutableDictionary *)_imgParams videoParms:(NSMutableDictionary *)_videoParams action:(NSString *)_action success:(void (^)(id))_success failure:(void (^)(NSError ... -
在NSMutableURLRequest的帮助下,我们通过使用我们自己的多部分POST请求实现解决了iOS上的问题。 仍然没有回答为什么我们不能使用AFNetworking或在Postman,Android和AngularJS上放置Content-Type标头。 我们有一种强烈的感觉,AFNetworking的问题是发送请求分块(header transfer-encoding: chunked )。 我们实际上在我们的自定义iOS实现上发送了Content-Type: multipart/form-dat ...
-
Objective-C如何使用AFNetworking发布表单数据?(Objective-C How to POST form-data using AFNetworking?)[2023-08-21]
你需要序列化你的params字典,然后对它进行字符串编码,因为你的body参数中有一个JSON对象。 试试这个: NSDictionary *params = @{@"email": @"email@gmail.com", @"name": @"myName"}; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:nil]; NSString *json = [[NSSt ... -
这篇文章可能有帮助。 尝试: [manager.operationQueue cancelAllOperations]; This post may help. Try: [manager.operationQueue cancelAllOperations];