런타임시 전체 화면 너비의 절반의 절반 크기로 imagview 및 textview 크기를 설정하고 싶습니다. 하지만 잘 작동하지 않습니다. 이미지 뷰는 총 화면 크기의 절반을 설정 한 후에 작게 표시됩니다.레이아웃보기가 주어진 크기에 맞지 않습니다.
이 문제를 해결하는 데 도움을주십시오. 지난 1 일부터 시도했지만 문제를 인식하지 못했습니다.
미리 감사드립니다.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/light_white" >
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/light_white" >
<TextView
android:id="@+id/noticeHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="15dip"
android:layout_marginTop="25dip"
android:textColor="@color/black"
android:textSize="18dip" />
<TextView
android:id="@+id/noticeContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/noticeHeading"
android:layout_below="@id/noticeHeading"
android:layout_marginTop="20dp"
android:textColor="@color/black"
android:textSize="16dip" />
<ImageView
android:id="@+id/noticeImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/noticeHeading"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_toRightOf="@id/noticeHeading" />
</RelativeLayout>
</ScrollView>
코드 :
View rootView = inflater.inflate(res, container, false);
noticeHeaderTextView = (TextView)rootView.findViewById(R.id.noticeHeading);
noticeContentTextView = (TextView)rootView.findViewById(R.id.noticeContent);
noticeImageView = (ImageView)rootView.findViewById(R.id.noticeImageView);
DisplayMetrics metrics = getResources().getDisplayMetrics();
int width = metrics.widthPixels;
noticeImageView.getLayoutParams().width = width/2;
noticeHeaderTextView.getLayoutParams().width = width/2;
noticeContentTextView.getLayoutParams().width = width/2;
변경된 뷰에서'requestLayout()'을 호출하십시오. (아마도'rootView'를 호출하는 것조차도 충분합니다) –
이것을 시도했지만 화면의 크기에 따라 방향이 바뀝니다. –
이미지에 일정한 너비를 주려고합니다. –