ImageView
画面の上部をTextView
その画像の左下に揃えようとしています。私は困惑しています、誰かが何が起こっているのか知っていますか?このように見せたい(グラフィカルデザイナーでは見栄えが良い)
これがアプリでの表示です。画像と画面上部の間に大きなスペースがあることに注意してください。
これがxmlです
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.package.blah.ImageWithOverlay
android:id="@+id/imageWithOverlay1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.package.blah.ImageWithOverlay>
</RelativeLayout>
これを生成するためのコードは次のとおりです。
public class ImageWithOverlay extends RelativeLayout {
ImageView image;
TextView text;
int imageHeight;
public ImageWithOverlay(Context context) {
super(context);
setupDisplay(context);
}
public ImageWithOverlay(Context context, AttributeSet attrs) {
super(context, attrs);
setupDisplay(context);
}
public ImageWithOverlay(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setupDisplay(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//super.onMeasure(widthMeasureSpec, heightMeasureSpec);
super.onMeasure(widthMeasureSpec, imageHeight);
}
private void setupDisplay(Context context) {
BitmapDrawable bd = (BitmapDrawable)this.getResources().getDrawable(R.drawable.flowers480);
imageHeight = bd.getBitmap().getHeight();
image = new ImageView(context);
image.setImageDrawable(bd);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.addRule(ALIGN_PARENT_TOP);
image.setLayoutParams(lp);
this.addView(image);
text = new TextView(context);
text.setText("testing");
lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.addRule(ALIGN_PARENT_BOTTOM);
text.setLayoutParams(lp);
this.addView(text);
}
}
どんな助けでもありがたいです、そして必要ならば追加の詳細を私に尋ねてください。