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);
}
}
도움이 필요하시면 언제든지 문의 해 주시기 바랍니다.
lp.addRule (RelativeLayout.ALIGN_BASELINE)을 사용하고 getBaseline 메서드를 재정 의하여 사용자 정의 위치에 배치 할 수 있습니다.이 블로그에는 원반이 있습니다. http://sudarnimalan.blogspot.sg/2011/09/android-aligning-custom -views-at-base.html –