package com.ql.model; import android.os.Parcel; import android.os.Parcelable; public class Stock implements Parcelable{ private String field_0;//代码+\n+名称 private String field_1;//最新+\n+金额 private String field_2;//涨幅 private String field_3;//涨跌 private String field_4;//雷达 //分时 private float[] field_5;//走势 private String field_6;//高点 private String field_7;//均线 private String field_8;//低点 public Stock(){ } public Stock(String field_0, String field_1, String field_2, String field_3, String field_4, float[] field_5, String field_6, String field_7, String field_8) { super(); this.field_0 = field_0; this.field_1 = field_1; this.field_2 = field_2; this.field_3 = field_3; this.field_4 = field_4; this.field_5 = field_5; this.field_6 = field_6; this.field_7 = field_7; this.field_8 = field_8; } public String getField_6() { return field_6; } public void setField_6(String field_6) { this.field_6 = field_6; } public String getField_7() { return field_7; } public void setField_7(String field_7) { this.field_7 = field_7; } public String getField_8() { return field_8; } public void setField_8(String field_8) { this.field_8 = field_8; } public float[] getField_5() { return field_5; } public void setField_5(float[] field_5) { this.field_5 = field_5; } public String getField_0() { return field_0; } public void setField_0(String field_0) { this.field_0 = field_0; } public String getField_1() { return field_1; } public void setField_1(String field_1) { this.field_1 = field_1; } public String getField_2() { return field_2; } public void setField_2(String field_2) { this.field_2 = field_2; } public String getField_3() { return field_3; } public void setField_3(String field_3) { this.field_3 = field_3; } public String getField_4() { return field_4; } public void setField_4(String field_4) { this.field_4 = field_4; } public static Parcelable.Creator getCreator() { return CREATOR; } @Override public int describeContents() { // TODO Auto-generated method stub return 0; } @Override public void writeToParcel(Parcel dest, int flags) { // TODO Auto-generated method stub dest.writeString(field_0); dest.writeString(field_1); dest.writeString(field_2); dest.writeString(field_3); dest.writeString(field_4); dest.writeFloatArray(field_5); dest.writeString(field_6); dest.writeString(field_7); dest.writeString(field_8); } public Stock(Parcel in) { this.field_0 = in.readString(); this.field_1 = in.readString(); this.field_2 = in.readString(); this.field_3 = in.readString(); this.field_4 = in.readString(); // in.readFloatArray(this.field_5);//似乎不行 this.field_5=in.createFloatArray();//可能不妥,看API this.field_6 = in.readString(); this.field_7 = in.readString(); this.field_8 = in.readString(); } @SuppressWarnings("unchecked") public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public Stock createFromParcel(Parcel in) { return new Stock(in); } public Stock[] newArray(int size) { return new Stock[size]; } }; }
//ArrayList<Stock> models={XXXXXXX}; //Intent intent=new Intent(MyStockActivity.this,MyStockSettingActivity.class); //传递 intent.putParcelableArrayListExtra("sockets", models); //startActivityForResult(intent, RESULT_CODE_SETTING); //读取 models=getIntent().getParcelableArrayListExtra("sockets");
Android高手进阶教程(十七)之---Android中Intent传递对象的两种方法(Serializable,Parcelable)!
http://blog.csdn.net/Android_Tutor/archive/2010/07/16/5740845.aspx
传递图片和复杂对象,复杂对象也需要实现Parcelable接口
package com.ata.model.receive; import android.graphics.Bitmap; import android.os.Parcel; import android.os.Parcelable; public class Exam implements Parcelable{ public String ad_md5;// public String buttons_md5;// public String etx_code;//考试编码 public String faq_md5;// public String is_etx;//0否1是 public String logo_url;//logourl public Bitmap bitmap;//logo_url对应的图标 public String news_md5;// public String sample_md5;// public String sample_url;//邮汇样张url public String sort;// public String status;//状态 public String test_name;//考试名称 public String test_name_short;// public String test_sponsor;//主办者 public String test_type;//考试类型 public String test_date;//当前批次考试日期 public String etx_id_desc;//当前批次说明 public String intro_url;//考试介绍url public String test_notice;//考试提醒 public String date_url;//考试日期 public String etx_id;// public int is_hot;//热门考试 public String account_notice;//帐号说明 public Bind bind;//复杂对象,绑定信息 public String getAccount_notice() { return account_notice; } public void setAccount_notice(String account_notice) { this.account_notice = account_notice; } public int getIs_hot() { return is_hot; } public void setIs_hot(int is_hot) { this.is_hot = is_hot; } public Bind getBind() { return bind; } public void setBind(Bind bind) { this.bind = bind; } public String getAd_md5() { return ad_md5; } public void setAd_md5(String ad_md5) { this.ad_md5 = ad_md5; } public String getButtons_md5() { return buttons_md5; } public void setButtons_md5(String buttons_md5) { this.buttons_md5 = buttons_md5; } public String getEtx_code() { return etx_code; } public void setEtx_code(String etx_code) { this.etx_code = etx_code; } public String getFaq_md5() { return faq_md5; } public void setFaq_md5(String faq_md5) { this.faq_md5 = faq_md5; } public String getIs_etx() { return is_etx; } public void setIs_etx(String is_etx) { this.is_etx = is_etx; } public String getLogo_url() { return logo_url; } public void setLogo_url(/blog_article/String logo_url/index.html) { this.logo_url = logo_url; } public String getNews_md5() { return news_md5; } public void setNews_md5(String news_md5) { this.news_md5 = news_md5; } public String getSample_md5() { return sample_md5; } public void setSample_md5(String sample_md5) { this.sample_md5 = sample_md5; } public String getSample_url() { return sample_url; } public void setSample_url(/blog_article/String sample_url/index.html) { this.sample_url = sample_url; } public String getSort() { return sort; } public void setSort(String sort) { this.sort = sort; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getTest_name() { return test_name; } public void setTest_name(String test_name) { this.test_name = test_name; } public String getTest_name_short() { return test_name_short; } public void setTest_name_short(String test_name_short) { this.test_name_short = test_name_short; } public String getTest_sponsor() { return test_sponsor; } public void setTest_sponsor(String test_sponsor) { this.test_sponsor = test_sponsor; } public String getTest_type() { return test_type; } public void setTest_type(String test_type) { this.test_type = test_type; } public String getTest_date() { return test_date; } public void setTest_date(String test_date) { this.test_date = test_date; } public String getEtx_id_desc() { return etx_id_desc; } public void setEtx_id_desc(String etx_id_desc) { this.etx_id_desc = etx_id_desc; } public String getIntro_url() { return intro_url; } public void setIntro_url(/blog_article/String intro_url/index.html) { this.intro_url = intro_url; } public String getTest_notice() { return test_notice; } public void setTest_notice(String test_notice) { this.test_notice = test_notice; } public String getDate_url() { return date_url; } public void setDate_url(/blog_article/String date_url/index.html) { this.date_url = date_url; } public String getEtx_id() { return etx_id; } public void setEtx_id(String etx_id) { this.etx_id = etx_id; } public Bitmap getBitmap() { return bitmap; } public void setBitmap(Bitmap bitmap) { this.bitmap = bitmap; } public static Parcelable.Creator<Exam> getCreator() { return CREATOR; } public int describeContents() { // TODO Auto-generated method stub return 0; } public void writeToParcel(Parcel dest, int flags) { // TODO Auto-generated method stub dest.writeString(ad_md5); dest.writeString(buttons_md5); dest.writeString(etx_code); dest.writeString(faq_md5); dest.writeString(is_etx); dest.writeString(logo_url); bitmap.writeToParcel(dest, flags); dest.writeString(news_md5); dest.writeString(sample_md5); dest.writeString(sample_url); dest.writeString(sort); dest.writeString(status); dest.writeString(test_name); dest.writeString(test_name_short); dest.writeString(test_sponsor); dest.writeString(test_type); dest.writeString(test_date); dest.writeString(etx_id_desc); dest.writeString(intro_url); dest.writeString(test_notice); dest.writeString(date_url); dest.writeString(etx_id); dest.writeInt(is_hot); dest.writeString(account_notice); dest.writeParcelable(bind, flags); } public static final Parcelable.Creator<Exam> CREATOR = new Creator<Exam>() { public Exam createFromParcel(Parcel source) { Exam instance = new Exam(); instance.ad_md5 = source.readString(); instance.buttons_md5 = source.readString(); instance.etx_code = source.readString(); instance.faq_md5 = source.readString(); instance.is_etx = source.readString(); instance.logo_url = source.readString(); instance.bitmap=Bitmap.CREATOR.createFromParcel(source); instance.news_md5 = source.readString(); instance.sample_md5 = source.readString(); instance.sample_url = source.readString(); instance.sort = source.readString(); instance.status = source.readString(); instance.test_name = source.readString(); instance.test_name_short = source.readString(); instance.test_sponsor = source.readString(); instance.test_type = source.readString(); instance.test_date = source.readString(); instance.etx_id_desc = source.readString(); instance.intro_url = source.readString(); instance.test_notice = source.readString(); instance.date_url = source.readString(); instance.etx_id = source.readString(); instance.is_hot = source.readInt(); instance.account_notice = source.readString(); instance.bind=source.readParcelable(Bind.class.getClassLoader()); return instance; } public Exam[] newArray(int size) { // TODO Auto-generated method stub return new Exam[size]; } }; }
Question:
Hi all,
I need your help!
I need to locate text on view as showed on the picture:
text 'Some more text' should be located in bottom|center_horizontal
text 'Short text' should be located on with align right, but about 10% from the top of the screen
text 'x.x.x.x' should be aligned to the center of the screen (right/bottom align of the 1st quater)
text 'Some long text ..' should be aligned to the top/left of the 3-rd quater of the screen, but it should cross the center_horizontal of the screen
eh ... something like this .. I hope, you're understand me :)
http://www.freeimagehosting.net/image.php?ca27bc012e.png
Please, help me!!!
Thanks for your help!
Answer:
Here a couple quick guidelines:
Looking again I your diagram, I reproduced it this way:
Unfortunately, nothing in step 4 worked correctly. Nothing like "layout_below" worked when the referenced item was a centerInParent item. with relative layouts to step 3. Turns out it had to do with failing to fill_content on the top level. Yes, the layouts are tricky, and I wish there was a debugger for them.
Here's the correct version:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/r1" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/short_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Short Text" android:gravity="right" android:layout_marginTop="30dip" android:layout_alignParentTop="true" /> <TextView android:id="@+id/more_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Some More Text" android:gravity="center" android:layout_alignParentBottom="true" /> <TextView android:id="@+id/centerpoint" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="0dip" android:height="0dip" /> <TextView android:id="@+id/run_fox" android:text="Run, fox, run!" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/centerpoint" android:layout_toLeftOf="@id/centerpoint" /> <TextView android:layout_below="@id/centerpoint" android:text="The quick brown fox jumped over the lazy dog, who had been a frog, and then got features and ran slowly." android:layout_alignRight="@id/centerpoint" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </RelativeLayout>
<TextView android:id="@+id/centerpoint" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="0dip" android:height="0dip" />
static final String tag = "GameView";
//声明GameThread类实例
GameThread gameThread;
public GameView(Context context) {
super(context);
// TODO Auto-generated constructor stub
//获取SurfaceHolder
SurfaceHolder surfaceHolder = getHolder();
//添加回调对象
surfaceHolder.addCallback(this);
//创建GameThread类实例
gameThread = new GameThread(surfaceHolder);
}
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
Log.v(tag, "surfaceChanged");
}
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
Log.v(tag, "surfaceCreated");
//启动gameThread
gameThread.start();
}
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
Log.v(tag, "surfaceDestroyed");
//通过结束run()函数的方法结束gameThread,详见GameThread类的定义
gameThread.run = false;
}
/**
* GameThread的定义
*
*/
class GameThread extends Thread {
SurfaceHolder surfaceHolder;
//run()函数中控制循环的参数。
boolean run = true;
public GameThread(SurfaceHolder surfaceHolder) {
this.surfaceHolder = surfaceHolder;
}
@Override
public void run() {
// TODO Auto-generated method stub
int i = 0;
while(run) {
Log.v(tag, "GameThread");
Canvas c = null;
try {
synchronized (surfaceHolder) {
//我们在屏幕上显示一个计数器,每隔1秒钟刷新一次
c = surfaceHolder.lockCanvas();
c.drawARGB(255, 255, 255, 255);
c.drawText("" + i++, 100, 100, new Paint());
Thread.sleep(1000);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (c != null) {
surfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
}
}