我想用javascript在html中的两个页面之间进行更改,但是当我更改时window.location,此句之后的代码将继续执行.
因此,当我这样做时,例如,getElementById()对它的调用无法识别该元素,因为页面仍在加载.
function myFun(){
// ...
window.location = 'page.html';
// ... wait until page.html is loaded
}
Run Code Online (Sandbox Code Playgroud)
我怎么能等到页面加载以避免这个问题?
我一直在寻找一个答案,但我找不到适合我的答案.我想在线性布局中将三张图片放在同一行中.我希望它们是ImageButtons,这是我的代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/ImageButton05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="@drawable/background" />
<ImageButton
android:id="@+id/ImageButton04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="@drawable/background" />
<ImageButton
android:id="@+id/ImageButton03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="@drawable/background" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我得到的问题是,由于图片"背景"太大,按钮的重量显示正确,而高度比预期的要大很多.它看起来像这样:
看起来像http://imageshack.us/a/img18/1516/x3qi.png
它看起来应该是这样的:
应该看看http://imageshack.us/a/img855/834/403t.png
如何在不指定dp大小的情况下解决这个问题?
如何在phonegap上使用javascript获取上一页?
我想返回(window.history.back())只有当我来自一个特定的html文件时,否则我想在按下后退按钮时转到另一个html页面.所以我想知道哪一个是历史的前一页.
我已经谷歌搜索了一段时间,我没有找到适合我的答案.
我必须将几张图片加载到主线程中,并且我想在发生这种情况时显示加载对话框,但不知怎的,我无法显示进度对话框...
我的代码如下:
private ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.background);
progress = ProgressDialog.show(this, "",getString(R.string.background_loading), true);
LoadBackgrounds loadB = new LoadBackgrounds();
new Thread(loadB).start();
}
public class LoadBackgrounds implements Runnable {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
loadPictures();
progress.dismiss();
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
loadPictures()必须在里面调用,runOnUiThread因为它修改了视图.那么,为什么在图片加载时没有显示进度对话框?