我在RelativeLayout的顶部放置了一个ImageView,但图像没有显示在页面顶部.我搜索了互联网并添加android:scaleType="fitStart"了问题并解决了问题,但是图像在页面中获得了更多空间,因为当我在此图像下方添加第二个图像时,第二个图像显示在页面的中心!问题是什么?我怎么解决这个问题?我尝试使用LinearLayout产生相同结果的a.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/registerAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:scaleType="fitStart"
android:src="@drawable/register_action" />
<ImageView
android:id="@+id/registerLogo"
android:src="@drawable/app_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_below="@id/registerAction"/>
<EditText
android:id="@+id/pass1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/registerLogo"
android:paddingTop="15dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:inputType="textPassword"
android:hint="@string/pass1"
android:gravity="right"/>
<EditText
android:id="@+id/pass2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/pass1"
android:paddingTop="15dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:inputType="textPassword"
android:hint="@string/pass2"
android:gravity="right"/>
<Button
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/pass2"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="30dp"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
Thanks.Cheers
编辑:和另一个问题如何在EditText下面填充Button 30dp?当我更改Button的PaddingTop时没有改变Button的位置.
我有这个按钮,当点击该按钮时,将在我的文本字段中输入的详细信息保存到 Google App Engine,在调用该 onClickListener 之后,我有一个启动新活动的意图,该活动显示我刚刚输入的详细信息。这是代码:
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == R.id.userDetailsCaptureButton) {
new EndpointsTask().execute(getApplicationContext());
}
startActivity(userProfileDisplayIntent);
}
});
Run Code Online (Sandbox Code Playgroud)
现在我希望能够在调用startActivityafter之前等待几秒钟new EnpointsTask().execute(getApplicationContext)。我读到使用Thread.sleep会导致 UI 冻结,因此不适合此操作。还有哪些其他选择?
我试图通过Google+显示登录到我的应用的用户的个人资料图片,但我不知道如何执行此操作.要获取图像(和其他信息),Google会提供代码
@Override
public void onConnected() {
...
if (mPlusClient.getCurrentPerson() != null) {
Person currentPerson = mPlusClient.getCurrentPerson();
String personName = currentPerson.getDisplayName();
String personPhoto = currentPerson.getImage();
String personGooglePlusProfile = currentPerson.getUrl();
}
}
Run Code Online (Sandbox Code Playgroud)
我知道,通常我需要得到我想从显示任何图像res/drawable...,但我不知道做什么用的价值做personPhoto(这在某种程度上得到的改变,从类型String到Image当粘贴在Eclipse中的代码.
我试图使用此方法将Facebook登录添加到我的应用程序,但我收到以下错误:
Error:(21, 13) error: package bolts does not exist
Error:(22, 13) error: package bolts does not exist
Error:(23, 13) error: package bolts does not exist
Error:(24, 13) error: package bolts does not exist
Error:(37, 49) error: cannot find symbol class AppLinkResolver
Error:(48, 32) error: cannot find symbol class AppLink
Error:(58, 12) error: cannot find symbol class Task
Error:(58, 17) error: cannot find symbol class AppLink
Error:(80, 12) error: cannot find symbol class Task
Error:(80, 26) error: cannot find …Run Code Online (Sandbox Code Playgroud) class background_thread extends AsyncTask<String ,String , Boolean > {
protected Boolean doInBackground(String... params) {
String UR = "127.0.0.1/abc/index.php";
try {
URL url = new URL(UR);
} catch(MalformedURLException e) {
e.printStackTrace();
}
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用上面的代码时,在HttpURLConnection中,url变为红色并且Android Studio显示错误无法解析符号url.代码有什么问题?
我使用Firebase来处理Android应用的Auth主题.我还在Firebase上保存了一个用户配置文件,其中包含用户ID和用户可以在Android应用中更新的额外选项.
启动时,应用程序会检查身份验证和身份验证.它重新加载用户配置文件(在Firebase上),然后在应用程序上更新我的userInstance.
Firebase在应用级别设置为离线功能.userInstance POJO在日志时与Firebase同步,并在unlog时停止同步.
我有一个特殊的参数,在我的用户配置文件中,我可以更改(作为管理员).
每次我在Firebase控制台上更新它时,它会在应用程序重新启动时替换为之前的值.
怎么会发生这种情况?
BTW:1 /如果多个客户端有不同的本地值,基于合并数据的机制?
这是更简单的代码,我试图重现错误.:
MyApplication.java
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Firebase.setAndroidContext(this);
Firebase.getDefaultConfig().setLogLevel(Logger.Level.DEBUG);
Firebase.getDefaultConfig().setPersistenceEnabled(true);
}
}
Run Code Online (Sandbox Code Playgroud)
主要活动
public class MainActivity extends AppCompatActivity {
Firebase ref;
User user;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ref = new Firebase("https://millezim-test.firebaseIO.com").child("user");
ref.keepSynced(true);
Button br = (Button) findViewById(R.id.b_read);
Button bs = (Button) findViewById(R.id.b_save);
final TextView tv_r = (TextView) findViewById(R.id.tv_value_toread);
final EditText tv_s = (EditText) findViewById(R.id.tv_value_tosave);
user = new User();
bs.setOnClickListener(new View.OnClickListener() …Run Code Online (Sandbox Code Playgroud) 我有一个带有图标和文字的按钮.
这是通过以下代码实现的:
<Button
...
android:drawableLeft="@drawable/ghana"
android:drawableStart="@drawable/ghana"
android:text="@string/hint_ghana"
/>
Run Code Online (Sandbox Code Playgroud)
我执行此操作时,数据绑定与文本一起使用但不与图标一起使用:
<Button
...
android:drawableLeft="@{countryOfResidence.thumbnail}"
android:drawableStart="@{countryOfResidence.thumbnail}"
android:text="@{countryOfResidence.countryName}"
/>
Run Code Online (Sandbox Code Playgroud)
这是结果:
我已经找到了解决方案,但找不到任何解决方案,因为大多数都专注于将图像加载到ImageView中.
我的Model类看起来像这样:
public class CountryOfResidence {
private String countryName;
private int thumbnail;
public CountryOfResidence(String countryName, int thumbnail) {
this.setCountryName(countryName);
this.setThumbnail(thumbnail);
}
....
Run Code Online (Sandbox Code Playgroud)
在onCreate()调用Activity 的方法中,我正在这样做
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivitySignUpBinding signUpBinding = DataBindingUtil.setContentView(this, R.layout.activity_sign_up);
MyHandler myHandler = new MyHandler();
signUpBinding.setMyHandler(myHandler);
mViewFlipper = (ViewFlipper) findViewById(R.id.signUpViewFlipper);
countryOfResidenceList = new ArrayList<>();
countryOfResidenceList.add(new CountryOfResidence("Nigeria", R.drawable.nigeria));
countryOfResidenceList.add(new CountryOfResidence("Ghana", R.drawable.ghana));
countryOfResidenceList.add(new CountryOfResidence("Kenya", R.drawable.kenya));
signUpBinding.setCountryOfResidence(countryOfResidenceList.get(1));
Run Code Online (Sandbox Code Playgroud)
最后,我的布局中的数据标签看起来像这样
<data> …Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个应用程序,其中实体通过其键Student添加到Class实体.所以在课堂上,我可以List通过他们的键可以识别一个学生,可以是Integer或String.But我不知道如何做到这一点.(请忍受我,这是我的第一个使用Python的项目)这里是我的代码:
import webapp2
from webapp2_extras import json
from google.appengine.ext import ndb
registrationPage = """
<html>
<head><title>Student Registration</title><head>
<body>
<h1>Student Registration</h1>
<form action="/" method="post">
<table border="1">
<tr><td>Srudent's BannerId</td><td><input type="number" size="6" name="banner_id"/></
td></tr>
<tr><td>Student's Name</td><td><input type="text" size="50" name="name"/></td></tr>
<tr><td><input type="submit" name="submit" value="Register Student"/></td></tr>
</table>
</form>
</body>
</html>
"""
class MathClass (ndb.Model):
class_Id = ndb.IntegerProperty(required=True)
professor_name = ndb.StringProperty(required=True)
number_of_students = ndb.IntegerProperty()
students = ndb.KeyProperty(repeated=True)
# A Class can return its data in JSON format
def toJSON(self):
jsonData …Run Code Online (Sandbox Code Playgroud) 我有一个类,Student有这个构造函数.
public Student(String name, int age, Map<String, Integer> grades) {
this.setName(name);
this.setAge(age);
this.setGrades(grades);
}
Run Code Online (Sandbox Code Playgroud)
在创建Student对象时,如何在构造函数中传递Map参数?
我们正在寻找的是类似的东西:
List<Student> roster = new ArrayList<>();
roster.add(new Student("Ann Droid", 145, Arrays.asList(96, 78)));
Run Code Online (Sandbox Code Playgroud)
如果我有这个构造函数:
public Student(String name, int age, List<Integer> grades) {
this.setName(name);
this.setAge(age);
this.setGrades(grades);
}
Run Code Online (Sandbox Code Playgroud) 我想在按下按钮后显示一个标签,但在按钮所做的操作完成后,我想隐藏标签。
这就是我试图做的
final Label loadingLabel = new Label();
loadingLabel.setText("Loading...");
loadingLabel.setFont(Font.font("Arial", 16));
BorderPane root = new BorderPane();
root.setRight(label);
root.setLeft(button);
root.setCenter(loadingLabel);
loadingLabel.setVisible(false);
final Button printButton = new Button("Print part");
printButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
loadingLabel.setVisible(true);
//here are some computations
loadingLabel.setVisible(false);
}
}
Run Code Online (Sandbox Code Playgroud)
代码根本不显示标签。
android ×7
java ×4
data-binding ×1
database ×1
firebase ×1
google-plus ×1
javafx ×1
label ×1
python ×1
try-catch ×1