我正在尝试以编程方式RelativeLayout在我的活动中添加一个上边距.使用xml我可以在这种模式下执行:android:layout_marginTop="10dp"但是当我尝试以编程方式执行时没有任何更改...正如您所看到的,我RelativeLayout在一个LinearLayout容器中使用了一些(有一个for循环).
这是我正在使用的代码:
//LINEAR LAYOUT
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
for (int i=1; i<=3; i++){
//RELATIVE LAYOUT
RelativeLayout relativeLayout = new RelativeLayout(this);
relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT));
relativeLayout.setBackgroundColor(getResources().getColor(R.color.grayColor));
//CODE FOR ADD MARGINS
RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams)relativeLayout.getLayoutParams();
relativeParams.topMargin=80;
relativeLayout.setLayoutParams(relativeParams);
//IMAGE VIEW
ImageView selectedPhoto = new ImageView(this);
selectedPhoto.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
selectedPhoto.setImageResource(R.drawable.ic_launcher);
//TEXT VIEWS
TextView numberCopies = new TextView(this);
numberCopies.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
numberCopies.setGravity(Gravity.CENTER);
numberCopies.setPadding(25, 25, 25, 25);
numberCopies.setTextColor(getResources().getColor(R.color.blackColor));
numberCopies.setText("2 copies ");
RelativeLayout.LayoutParams layoutParamsNumberCopies = …Run Code Online (Sandbox Code Playgroud) 我在Google Play商店发布了一个简单的应用程序.现在我需要创建一个qr代码,在阅读时直接打开我在Play商店的应用程序页面.有可能吗?实际上,我已经为测试创建了一个qr代码,但每次设备读取它时,会出现一个小框,并询问我是否要打开Chrome,浏览器或Play商店的链接.我可以避免这个盒子的展示并直接进入Play商店吗?
谢谢
我创建了一个服务器套接字,它接受来自客户端的连接,当建立连接时,使用写入字节的 OutputStream 将图像传输到它。我的问题是如何在关闭套接字连接之前检查 OutputStream 是否已完成写入字节,因为有时并非所有图像都正确传输。这是我正在使用的代码:
File photoFile = new File(getHeader); //getHeader is the file that i have to transfer
int size2 = (int) photoFile.length();
byte[] bytes2 = new byte[size2];
try {
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(photoFile));
buf.read(bytes2, 0, bytes2.length);
buf.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
client.getOutputStream().write(bytes2, 0, size2); //client is the server socket
Run Code Online (Sandbox Code Playgroud)
谢谢
我需要在没有加载的情况下读取图像的属性或下载它.事实上,我已经实现了一个使用CGImageSourceCreateWithUrl来完成此任务的简单方法.我的问题是它总是返回错误,因为似乎imageSource为null.那么我能做些什么来修复呢?在NSURL对象中,我传递的网址如:" http://www.example.com/wp-content/uploads/image.jpg ",还有用于检索手机内部图像的ALAssets库ID,例如"assets-library://资产/ asset.JPG?ID = E5F41458-962D-47DD-B5EF-E606E2A8AC7A&EXT = JPG".这是我的方法:
-(NSString *) getPhotoInfo:(NSString *)paths{
NSString *xmlList = @“test”;
NSURL * imageFileURL = [NSURL fileURLWithPath:paths];
NSLog(@"imageFileURL %@", imageFileURL);
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)(imageFileURL), NULL);
if (imageSource == NULL) {
// Error loading image
NSLog(@"Error loading image");
}
CGFloat width = 0.0f, height = 0.0f;
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
NSLog(@"image source %@", imageSource);
return xmlList;
}
Run Code Online (Sandbox Code Playgroud)
我已经看到这个帖子试图解决它但似乎没有任何工作:
在我的项目中,ARC已启用.
谢谢