我正在尝试在Google Glass上显示HTML页面。我设法做到了,但页面不可滚动。这是我的代码:
package com.example.dbe13509.testglass;
import com.google.android.glass.media.Sounds;
import com.google.android.glass.widget.CardBuilder;
import com.google.android.glass.widget.CardScrollAdapter;
import com.google.android.glass.widget.CardScrollView;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.AdapterView;
import java.io.File;
/**
* An {@link Activity} showing a tuggable "Hello World!" card.
* <p>
* The main content view is composed of a one-card {@link CardScrollView} that provides tugging
* feedback to the user when swipe gestures are detected.
* If your Glassware intends to intercept swipe gestures, you should set the content view directly
* and use a {@link com.google.android.glass.touchpad.GestureDetector}.
* @see <a href="https://developers.google.com/glass/develop/gdk/touch">GDK Developer Guide</a>
*/
public class MainActivity extends Activity {
/** {@link CardScrollView} to use as the main content view. */
private CardScrollView mCardScroller;
WebView web;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
web = new WebView(this);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://www.google.fr");
File lFile = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/test.html");
web.loadUrl("file:///" + lFile.getAbsolutePath());
mCardScroller = new CardScrollView(this);
mCardScroller.setAdapter(new CardScrollAdapter() {
@Override
public int getCount() {
return 1;
}
@Override
public Object getItem(int position) {
return web;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return web;
}
@Override
public int getPosition(Object item) {
if (web.equals(item)) {
return 0;
}
return AdapterView.INVALID_POSITION;
}
});
// Handle the TAP event.
mCardScroller.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Plays disallowed sound to indicate that TAP actions are not supported.
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.playSoundEffect(Sounds.DISALLOWED);
}
});
setContentView(web);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
}
/**
* Builds a Glass styled "Hello World!" view using the {@link CardBuilder} class.
*/
private View buildView() {
CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
// card.setText(R.string.hello_world);
// web.loadUrl("http://www.google.fr");
return card.getView(web, null);
}
}
我尝试使用CardScrollView
失败了。我想我需要在某个地方制作一些自定义课程,但我找不到相关的文档,而且我是Glass的初学者,所以如果有人可以帮助我......