我有一个ListAdapter,它有很多不同的行布局.要拥有一个干净的代码,我想从View类中的适配器的getView()外包行的布局.是否可以将XML布局扩展为自定义视图?我只找到了LayoutInflater,但它返回了一个View,但没有帮助.我想要一个类似于Activity的setLayout()的东西.这可能吗?
谢谢!
我正在通过nodejs将java应用程序中的压缩数据发送到网页.使用java deflater和base64编码压缩数据.在网页上我试图用https://github.com/dankogai/js-deflate来扩充数据,但它不起作用(空结果).我错过了什么吗?
Java方面:
private String compress(String s) {
DeflaterOutputStream def = null;
String compressed = null;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
// create deflater without header
def = new DeflaterOutputStream(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
def.write(s.getBytes());
def.close();
compressed = Base64.encodeBase64String(out.toByteArray());
System.out.println(compressed);
} catch(Exception e) {
Log.c(TAG, "could not compress data: " + e);
}
return compressed;
}
Run Code Online (Sandbox Code Playgroud)
Javascript方面:
var data = RawDeflate.inflate(Base64.fromBase64(compressed));
Run Code Online (Sandbox Code Playgroud) 我有一个ViewFlipper应该对一个投掷手势作出反应,但事实并非如此.
活动
@Override
public void onCreate(Bundle savedInstanceState) {
...
listView = this.getListView();
detector = new GestureDetector(this, new FlingGestureListener(listView));
...
}
Run Code Online (Sandbox Code Playgroud)
FlingGestureListener
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
int pos = source.pointToPosition(Math.round(e1.getX()), Math.round(e1.getY()));
View v = source.getChildAt(pos - source.getFirstVisiblePosition());
System.out.println("fling: x=" + velocityX + " y=" + velocityY);
try {
IFlingable flingable = (IFlingable) v;
if(velocityY > -200 && velocityY < 200) {
if(velocityX < 0)
flingable.fling(IFlingable.RIGHT_TO_LEFT);
else if(velocityX > 0)
flingable.fling(IFlingable.LEFT_TO_RIGHT);
}
} catch(Exception e) …Run Code Online (Sandbox Code Playgroud) 我有多个的情节geom_point和一个stat_function在ggplot2.有没有办法展示一个传奇?
df <- data.frame("x"=c(1:5), "a"=c(1,2,3,3,3), "b"=c(1,1.1,1.3,1.5,1.5))
df <- melt(df, "x")
p <- ggplot(df, aes(x=x, y=value)) +
geom_point(aes(colour=variable, shape=variable)) +
stat_function(aes(colour="log2(x)"), fun=log2)
Run Code Online (Sandbox Code Playgroud)
我希望有一个蓝色线条和两个彩色形状的传奇.我试过了
scale_colour_discrete(name="legend", breaks=c("a", "b", "log2(x)")) +
scale_shape_discrete(name="legend", breaks=c("a", "b"))
Run Code Online (Sandbox Code Playgroud)
但这不起作用.有没有办法自动或手动执行此操作?
提前致谢.
我已经构建了一个自定义对话框,顶部和底部都有黑线.它们只出现在Galaxy S2上.在其他一些设备上它看起来不错.是否有一个属性我必须设置摆脱它们?

这是我的代码:
public class MyDialog extends Dialog {
private Context context;
private String title, message;
private TextView titleView, messageView;
private ImageView icon;
private int iconRes;
private boolean spin;
public MyDialog(Context context, int icon, boolean spin, String title, String message) {
...
}
private void init() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.my_dialog);
...
}
}
Run Code Online (Sandbox Code Playgroud)
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:minWidth="300dip" style="@style/basic" android:orientation="vertical">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="@drawable/titlebar_bg"
android:orientation="horizontal" android:gravity="center_vertical"
android:paddingBottom="5sp">
<ImageView android:src="@drawable/info" android:id="@+id/dialogIcon"
android:layout_height="32sp" android:layout_width="32sp" />
<TextView android:id="@+id/titleText" android:text="Title"
android:textSize="20sp" …Run Code Online (Sandbox Code Playgroud) 我在我的Java应用程序中下载了一些文件并实现了下载监视器对话框.但最近我使用gzip压缩了所有文件,现在下载监视器有点破碎了.
我将文件作为a打开,GZIPInputStream并在每次下载KB后更新下载状态.如果文件的大小为1MB,则进度上升到例如4MB,这是未压缩的大小.我想监视压缩的下载进度.这可能吗?
编辑:澄清:我正在读取GZipInputStream中的字节,这些字节是未压缩的字节.所以这并没有给我正确的文件大小.
这是我的代码:
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.connect();
...
File file = new File("bibles/" + name + ".xml");
if(!file.exists())
file.createNewFile();
out = new FileOutputStream(file);
in = new BufferedInputStream(new GZIPInputStream(con.getInputStream()));
byte[] buffer = new byte[1024];
int count;
while((count = in.read(buffer)) != -1) {
out.write(buffer, 0, count);
downloaded += count;
this.stateChanged();
}
...
private void stateChanged() {
this.setChanged();
this.notifyObservers();
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
在此条形图中,条形图的缩放方式不同。因此 y 轴的排序不正确 (157 > 1342.6)。我该如何解决?
library(reshape)
library(ggplot2)
data <- matrix(1:9, 3, 3)
colnames(data) <- c("approach", "best", "worst")
data[1,] <- c("a", 1.8, 157.0)
data[2,] <- c("b", 592.3, 1342.6)
data[3,] <- c("c", 613.1, 3744.1)
data <- as.data.frame(data)
data <- melt(data, id="approach")
p <- ggplot(data, aes(x=approach, y=value, fill=variable)) +
geom_bar(position="dodge", stat="identity")
p
Run Code Online (Sandbox Code Playgroud)

提前致谢。