Skip to content

Instantly share code, notes, and snippets.

@xloger
xloger / GenerateValueFiles.java
Created April 25, 2018 10:11
Android 百分比布局
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
/**
* Created by zhy on 15/5/3.
* 代码来自:blog.csdn.net/lmj623565791/article/details/45460089
* 首先 javac GenerateValueFiles 编译,然后 java GenerateValueFiles 运行
* 默认宽高为1280*720,如需修改可在命令后添加参数,例如java GenerateValueFiles 750 1334。
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_mine, container, false)
view.mine_recycler_view.adapter = SimpleAdapter<MineActionItem>(mineActionItem,R.layout.item_mine) { holder, item ->
holder.itemView.item_mine_icon.imageResource = item.icon
holder.itemView.item_mine_title.text = item.name
holder.itemView.item_mine_tip.text = item.info
holder.itemView.setOnClickListener {
toast("$item 被点击了")
}
}
class SimpleAdapter<T>(val list: List<T>, val layoutResource: Int, val bind: (holder: ViewHolder, t : T) -> Unit) : RecyclerView.Adapter<SimpleAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(parent.context).inflate(layoutResource, parent, false))
}
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
bind(holder, list[position])
}
class MineFragment : BaseFragment() {
private val mineActionItem = listOf<MineActionItem>(MineActionItem(R.drawable.bill, "账单"),
MineActionItem(R.drawable.member, "中兴会员", "3,765 积分"),
MineActionItem(R.drawable.assets, "总资产", "开启粮食储蓄保障"),
MineActionItem(R.drawable.balance, "余额", "10.00 元"),
MineActionItem(R.drawable.service, "粮食服务"),
MineActionItem(R.drawable.love, "爱心捐赠"))
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
/**
* Quality level corresponding to the lowest available resolution.
*/
public static final int QUALITY_LOW = 0;
/**
* Quality level corresponding to the highest available resolution.
*/
public static final int QUALITY_HIGH = 1;
package com.xloger.unitylib;
import android.util.Log;
import java.util.LinkedList;
import java.util.Queue;
/**
* Created on 2017/3/7 11:10.
* Editor:xloger
package com.xloger.exlink.app;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import com.xloger.exlink.app.entity.App;
import com.xloger.exlink.app.entity.Rule;
import com.xloger.exlink.app.util.AppUtil;
import com.xloger.exlink.app.util.MyLog;
> There are typically two ways to use Go on Android and iOS. The first is to write a Go library and use `gomobile bind` to generate language bindings for Java and Objective-C. Building a library does not require the app package. The `gomobile bind` command produces output that you can include in an Android Studio or Xcode project. For more on language bindings, see https://golang.org/x/mobile/cmd/gobind.
The second way is to write an app entirely in Go. The APIs are limited to those that are portable between both Android and iOS, in particular OpenGL, audio, and other Android NDK-like APIs. An all-Go app should use this app package to initialize the app, manage its lifecycle, and receive events.
引用自<https://godoc.org/golang.org/x/mobile/app>
第一种方式,也就是目前我们项目里所做的,采用 Go 生成 RPC 文件,然后在 Android 项目里可以调用它。第二种方式,由于 Android 平台本身就是 Java 写的,大量 API 本身就是基于 Java 的,想封装起来工作量会很大,几乎不现实。而 Android 的 NDK API 是基于 C 写的,所以 GoMobile 把这部分封装了,使得可以用 Go 开发游戏,这些基于 OpenGL 实现的跨平台应用。
所以初步分析,用 GoMobile 是不能实现『用 Go 编写跨平台的 FastLemon』 这样的功能的。然