导入依赖
compile 'com.android.support:recyclerview-v7:25.3.1' compile 'com.android.support:support-v4:25.3.1' compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.alibaba:fastjson:1.1.46.android' compile 'com.taobao.android:weex_sdk:0.10.0@aar' compile 'com.qiyukf.unicorn:unicorn:3.5.0'
另外联网获取图片框架的依赖
compile 'com.squareup.picasso:picasso:2.5.2'
Androidmainfest清单文件加入
<application
android:name=".WXApplication"
MainActivity</application>
activity_main.xml<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_network" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> </RelativeLayout>
package com.yunxun.weex; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import com.taobao.weex.IWXRenderListener; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.common.WXRenderStrategy; import java.util.HashMap; import java.util.Map; public class MainActivity extends AppCompatActivity implements IWXRenderListener { private static String TEST_URL = "http://online.youchang88.com/salesAssist/shopDetail.js"; private WXSDKInstance mWXSDKInstance; private FrameLayout mContainer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContainer = (FrameLayout) findViewById(R.id.container); mWXSDKInstance = new WXSDKInstance(this); mWXSDKInstance.registerRenderListener(this); /** * pageName:自定义,一个标示符号。 * url:远程bundle JS的下载地址 * options:初始化时传入WEEX的参数,比如 bundle JS地址 * flag:渲染策略。WXRenderStrategy.APPEND_ASYNC:异步策略先返回外层View,其他View渲染完成后调用onRenderSuccess。WXRenderStrategy.APPEND_ONCE 所有控件渲染完后后一次性返回。 */ Map<String, Object> options = new HashMap<>(); options.put(WXSDKInstance.BUNDLE_URL, TEST_URL); mWXSDKInstance.renderByUrl("WXSample",TEST_URL,options,null, WXRenderStrategy.APPEND_ONCE); } @Override protected void onStart() { super.onStart(); if (mWXSDKInstance != null) { mWXSDKInstance.onActivityStart(); } } @Override protected void onResume() { super.onResume(); if (mWXSDKInstance != null) { mWXSDKInstance.onActivityResume(); } } @Override protected void onPause() { super.onPause(); if (mWXSDKInstance != null) { mWXSDKInstance.onActivityPause(); } } @Override protected void onStop() { super.onStop(); if (mWXSDKInstance != null) { mWXSDKInstance.onActivityStop(); } } @Override protected void onDestroy() { super.onDestroy(); if (mWXSDKInstance != null) { mWXSDKInstance.onActivityDestroy(); } } @Override public void onViewCreated(WXSDKInstance instance, View view) { if (view.getParent() != null) { ((ViewGroup) view.getParent()).removeView(view); } mContainer.addView(view); } @Override public void onRenderSuccess(WXSDKInstance instance, int width, int height) { } @Override public void onRefreshSuccess(WXSDKInstance instance, int width, int height) { } @Override public void onException(WXSDKInstance instance, String errCode, String msg) { } }
加入类
PhoneInfoModule
RichTextWeexEventImageAdapterWXApplication这几个类可以在官方介绍找到 https://github.com/xkli/WXSample.git另外要在ImageAdapter中实现你自己的图片下载如下
|
我的实现可以在源码中看到.
http://download.csdn.net/detail/m0_37855088/9834335