在这个页面中,@+id/photo_area
是动态生成的,因为我希望宽度与高度对齐,所以我写了下面的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/share_bg" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:overScrollMode="never" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/photo_area"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/share_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/photo_area"
android:layout_above="@+id/share_content"
android:layout_marginLeft="20dp"
android:text="@string/share_title"
android:textColor="@android:color/white" />
<EditText
android:id="@+id/share_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/share_submit"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/custom_textarea"
android:gravity="top|left"
android:lines="5"
android:scrollbars="vertical"
android:text="@string/default_msg" />
<ImageView
android:id="@+id/share_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:src="@drawable/photo_taken_btn_submit" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
在程序中,我在照片上设置了参数
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.share_pic_form);
ctx = this;
prefs = ctx.getSharedPreferences("userInfo", 0);
editor = prefs.edit();
tracker = EasyTracker.getInstance(this);
permission = new ArrayList<String>();
permission.add("email");
Utility.setHeader(this,R.string.selfie_header,false);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, callback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setPermissions(permission).setCallback(callback));
}
}
photoArea = (ImageView) findViewById(R.id.photo_area);
int size = (int)(Utility.getScreenWidth(this));
RelativeLayout.LayoutParams imgParams = new RelativeLayout.LayoutParams(size, size);
imgParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
//imgParams.addRule(RelativeLayout.ABOVE, R.id.share_title);
photoArea.setAdjustViewBounds(true);
photoArea.setLayoutParams(imgParams);
photoArea.setBackgroundResource(android.R.color.darker_gray);
photoArea.getBackground().setAlpha(204); // = 0.8 alpha
shareTitle = (TextView) findViewById(R.id.share_title);
shareContent = (EditText) findViewById(R.id.share_content);
if (getIntent() != null) {
Intent intent = getIntent();
fileUri = (String) intent.getStringExtra("photo");
catId = (String) intent.getStringExtra("catId");
} else if (savedInstanceState != null){
mBitmap = (Bitmap) savedInstanceState.getParcelable("bitmap") == null ? null : (Bitmap) savedInstanceState.getParcelable("bitmap");
catId = (String) savedInstanceState.getString("catId");
}
FileInputStream inputStream = null;
File imgSelected = new File(fileUri);
try {
inputStream = new FileInputStream(imgSelected);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ctx, ctx.getResources().getString(R.string.get_photo_error), Toast.LENGTH_SHORT).show();
finish();
}
mBitmap = Utility.decodeBitmap(inputStream, 1280, 960);
if (mBitmap == null) {
Toast.makeText(ctx, ctx.getResources().getString(R.string.get_photo_error), Toast.LENGTH_SHORT).show();
finish();
} else {
photoArea.setImageBitmap(mBitmap);
sharePhotoBtn = (ImageView) findViewById(R.id.share_submit);
sharePhotoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tracker.send(MapBuilder.createEvent("form_button","Category_form","SubmitnShare_" + Utility.getLocale(ctx),null).build());
performPublish(PendingAction.POST_PHOTO);
}
});
}
}
The problem is , in the xml /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.share_pic_form);
ctx = this;
prefs = ctx.getSharedPreferences("userInfo", 0);
editor = prefs.edit();
tracker = EasyTracker.getInstance(this);
permission = new ArrayList<String>();
permission.add("email");
Utility.setHeader(this,R.string.selfie_header,false);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, callback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setPermissions(permission).setCallback(callback));
}
}
photoArea = (ImageView) findViewById(R.id.photo_area);
int size = (int)(Utility.getScreenWidth(this));
RelativeLayout.LayoutParams imgParams = new RelativeLayout.LayoutParams(size, size);
imgParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
//imgParams.addRule(RelativeLayout.ABOVE, R.id.share_title);
photoArea.setAdjustViewBounds(true);
photoArea.setLayoutParams(imgParams);
photoArea.setBackgroundResource(android.R.color.darker_gray);
photoArea.getBackground().setAlpha(204); // = 0.8 alpha
shareTitle = (TextView) findViewById(R.id.share_title);
shareContent = (EditText) findViewById(R.id.share_content);
if (getIntent() != null) {
Intent intent = getIntent();
fileUri = (String) intent.getStringExtra("photo");
catId = (String) intent.getStringExtra("catId");
} else if (savedInstanceState != null){
mBitmap = (Bitmap) savedInstanceState.getParcelable("bitmap") == null ? null : (Bitmap) savedInstanceState.getParcelable("bitmap");
catId = (String) savedInstanceState.getString("catId");
}
FileInputStream inputStream = null;
File imgSelected = new File(fileUri);
try {
inputStream = new FileInputStream(imgSelected);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ctx, ctx.getResources().getString(R.string.get_photo_error), Toast.LENGTH_SHORT).show();
finish();
}
mBitmap = Utility.decodeBitmap(inputStream, 1280, 960);
if (mBitmap == null) {
Toast.makeText(ctx, ctx.getResources().getString(R.string.get_photo_error), Toast.LENGTH_SHORT).show();
finish();
} else {
photoArea.setImageBitmap(mBitmap);
sharePhotoBtn = (ImageView) findViewById(R.id.share_submit);
sharePhotoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tracker.send(MapBuilder.createEvent("form_button","Category_form","SubmitnShare_" + Utility.getLocale(ctx),null).build());
performPublish(PendingAction.POST_PHOTO);
}
});
}
}
问题是,the layout_below photo_area
的{{1}}无效。似乎photo_area是最重要的,如何解决问题?感谢
答案 0 :(得分:3)
根据文档layout_below
:
Positions the top edge of this view below the given anchor view ID.
所以,是的,您案例中的照片区域将高于
您可能希望更改为layout_above