我有一个全屏PNG,我想在飞溅中显示.只有一个错误,我不知道该怎么把大小在每个绘制的文件夹(ldpi,mdpi,hdpi,和xhdpi).我的应用程序应该在所有手机和平板电脑上运行良好和美观.我应该创建什么尺寸(以像素为单位),以便在所有屏幕上显示漂亮的效果?
我最近开始使用Android Studio v0.1.1,而我似乎无法找到LogCat ......它消失了吗?或者如果没有,我该如何启用它?
如果它消失了,有没有办法启用类似的东西来记录我的应用程序行为(主要是崩溃)?
我最近开始用C编程,来自Java和Python.现在,在我的书中,我注意到要制作一个"Hello World"程序,语法是这样的:
char message[10]
strcpy(message, "Hello, world!")
printf("%s\n", message);
Run Code Online (Sandbox Code Playgroud)
现在,这个例子使用了一个char数组,我想知道 - 字符串发生了什么?为什么我不能简单地使用其中一个?也许有不同的方法来做到这一点?
我已经开始使用Google+ APIfor android了,我已经按照本教程创建了一个登录应用程序:
https://developers.google.com/+/mobile/android/sign-in
现在,问题是我想从一个不同的创建注销按钮Activity,我试图做的事情并没有真正起作用..
我的GPlusLogin代码(Google+登录活动):
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import com.google.android.gms.common.*;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.plus.PlusClient;
public class GPlusLogin extends Activity implements ConnectionCallbacks, OnConnectionFailedListener{
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private static final String TAG = "GPlusLogin";
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.gplus_layout);
mPlusClient = …Run Code Online (Sandbox Code Playgroud) 我有一个imageView,我想显示你当前所在国家的一个小图标.我可以获得国家代码,但问题是我无法动态更改imageView资源.我的图片文件都是小写的(例如:国家代码= US,图片文件=我们)
我的代码(countryCode是大写字母的当前countryCode):
String lowerCountryCode = countryCode.toLowerCase();
String resource = "R.drawable." + lowerCountryCode;
img.setImageResource(resource);
Run Code Online (Sandbox Code Playgroud)
现在,当然这不起作用因为setImageResource想要一个int,所以我该怎么做呢?提前致谢
我有一个javascript文件,在带有<article>标记的每个元素上设置一个'click'的EventListener .我希望在事件触发时获得点击文章的ID.出于某种原因,我的代码什么都没有!
我的javascript:
articles = document.getElementsByTagName('article');
articles.addEventListener('click',redirect(e),false);
function redirect(e){
alert(e.target.id);
}
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?BTW我的文章设置是在窗口加载时调用的函数,我知道这是有效的,因为该函数有其他功能.
编辑
所以我修复了我的代码,所以它将循环并将监听器添加到每个文章元素,现在我得到一个没有任何内容的警报框.当尝试输出没有ID的e.target时,我会为每个元素获得以下消息:
[object HTMLHeadingElement]
Run Code Online (Sandbox Code Playgroud)
有什么建议?
另一个编辑
我目前的javascript代码:
function doFirst(){
articles = document.getElementsByTagName('article');
for (var i = 0; i < articles.length; i++) {
articles[i].addEventListener('click',redirect(articles[i]),false);
}
}
function redirect(e){
alert(e.id);
}
window.addEventListener('load',doFirst,false);
Run Code Online (Sandbox Code Playgroud)
这是在页面完成加载时显示我的警告框,而没有考虑到我没有点击该死的东西:O
在我的SQLite安装程序类中,我有一个DbHelper,它需要一个Context作为它的一部分.要设置上下文,我只在我的SQLite类中使用一个构造函数,它需要一个上下文作为参数的一部分.
但我刚遇到一个问题.当我试图从一个不是Activity的类中调用我的SQLite类时,我无法使用context classname.this它,它正在困扰我.
我也尝试这样做来声明一个上下文:
protected Context context;
Run Code Online (Sandbox Code Playgroud)
然后再打电话给它:
SetSql PlayerObject = new SetSql(This.context);
Run Code Online (Sandbox Code Playgroud)
但这也不起作用.
有什么建议吗?
我在我的应用程序中使用了RatingBar元素,并尝试使用OnRatingChangedListener进行设置.在监听器中,我使用变量上的if语句来做不同的事情.问题是,出于某种原因,当我有多个选项时,这个监听器无法正常工作.它是在onCreate()方法中设置的,在if语句中的变量获取值之前,但我试图将它移动到其他位置而根本没有成功.
我的onCreate():
bar = (RatingBar) findViewById(R.id.serviceLevel);
bar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
if(Code==null){
Toast.makeText(TipCalculatorActivity.this, "Locationing error occured, please report to the developer.", Toast.LENGTH_LONG).show();
}else if(Code=="1"){
if(rating==0){
autochange.setText("Precentage: 0%");
precentage = 0;
calculate(value, precentage);
}else if(rating==0.5){
autochange.setText("Precentage: 10%");
precentage = 8;
calculate(value, precentage);
}else if(rating==1){
autochange.setText("Precentage: 11%");
precentage = 9;
calculate(value, precentage);
}else if(rating==1.5){
autochange.setText("Precentage: 11%");
precentage = 10;
calculate(value, precentage);
}else if(rating==2){
autochange.setText("Precentage: 12%");
precentage = 11;
calculate(value, precentage);
}else if(rating==2.5){
autochange.setText("Precentage: 12%"); …Run Code Online (Sandbox Code Playgroud) 我有这个项目,我有一个比屏幕大小更大的位图.我想调整它以适应屏幕.我没有标题栏,而且我处于全屏模式.这是我的非工作代码:
public class ScopView extends View
{
private Scop thescop;
public ScopView(Context context, Scop newscop)
{
super(context);
this.thescop = newscop;
}
@Override
public void onDraw(Canvas canvas)
{
Bitmap scopeBitmap;
BitmapFactory.Options bfOptions = new BitmapFactory.Options();
bfOptions.inDither = false;
bfOptions.inPurgeable = true;
bfOptions.inInputShareable = true;
bfOptions.inTempStorage = new byte[32 * 1024];
scopeBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.scope, bfOptions);
scopeBitmap.createScaledBitmap(scopeBitmap, SniperActivity.Width, SniperActivity.Height, false);
canvas.drawBitmap(scopeBitmap, SniperActivity.scopx, SniperActivity.scopy, null);
}
}
Run Code Online (Sandbox Code Playgroud)
在这里使用createScaledBitmap方法时,我将自己用作源,并使用一个活动中的一些变量来从屏幕首选项中检索窗口高度和宽度.